This is the URL
http://www.example.com/main/index.php?p=test
I want it to become this
http://www.example.com/test
My current .htaccess looks like this
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^template\/?(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301,L]
RewriteCond %{THE_REQUEST} \s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteRule ^([^./]*)/?$ /index.php/?p=$1 [L,QSA]
With these rules i only get this at the end
/main/
I have tried many other Rewrite Rules but this rule seems to be the closest i can get.
MY FIX
RewriteEngine On
RewriteRule ^([^/]*)\/$ /main/index.php?p=$1 [L]
It does not do exactly what i wanted but i is a close as i can get and work. Instead of seeing http://www.example.com/main/index.php?p=test we see http://www.example.com/main/test/ Was hoping for /test but /test/ will do. I also have to have this in each sub folder and change /main/ to the folder name, but that is automated so i am not that worried about it Thank you all for your help.
Remove the leading slash. .htaccess
is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule
URI pattern.
Try this rule:
RewriteEngine on
RewriteRule ^template/?(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteRule ^([^./]+)/?$ /index.php/?p=$1 [L,QSA]
Place the .htaccess file in root (/) not main folder (/main)
UPDATE
RewriteEngine On
RewriteRule ^(.*?)$ main/index.php?p=$1 [QSA]
Please try the above
You said you have this in the root directory, therefore you need to add main to your htaccess regex otherwise the code will point to the wrong directory. Let me know if this works
# add /main
RewriteCond %{THE_REQUEST} \s/+main/index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
#add /main
RewriteRule ^([^./]*)/?$ /main/index.php/?p=$1 [L,QSA]
Note: I tested this on one of my websites and it worked