1

I'm trying to add .htaccess for specific page in wordpress child theme. Actually i'm sending category slug in url to custompostpage.php displaying post by category slug. For getting the category slug i'm using cp= action at end of the url.

http://example.com/demo/project/custom-post-page/?cp=search-engine-marketing

Functionality working fine.. But I want to remove the ?cp= for SEO purpose. For the task i'm using following .htaccess

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^custom-post-page/([^.]*)$ custom-post-page?cp=$1 [QSA,L]
</IfModule>

But it does not working. I upload this .htaccess file in the child theme (same path of custompostpage.php).

Can anyone guide me that can i add .htaccess file in the child theme using wordpress or not? If yes then where i'm doing wrong in my coding. I would like to appreciate if someone guide me. Thank You

Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68

1 Answers1

0

The rewrite rule needs fixing as your url doesn't start with custom-post-page

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)custom-post-page/([^\.]*)$ $1custom-post-page?cp=$2 [QSA,L]
</IfModule>
the-noob
  • 1,322
  • 2
  • 14
  • 19
  • Thanks for share the knowledge, but still nothing happening. I added your code but does not working. – Ayaz Ali Shah Apr 13 '16 at 10:11
  • In your original example the `([^.]*)` is wrong as it excludes anything (dot), you forgot to escape that `([^\.]*)`. I fixed my example, should work now. If you have control over the Apache server I recommend [debugging the rewrite](http://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite) – the-noob Apr 13 '16 at 13:58
  • Thanks for your answer, but `.htaccess` file does not work. Nothing happening. I place this file on same path where `custompostpage.php` is located... – Ayaz Ali Shah Apr 13 '16 at 14:06
  • If you are using Wordpress you need to edit the already existing `.htaccess` and add the `RewriteRule` – the-noob Apr 13 '16 at 14:16