.htaccess Pretty rewrite URL for PHP pages in subfolder?

I have the following directory setup:

http://www.mysite.com/public/

I use the following correspondence to remove a β€œpublic” folder from visible URLs:

 #rewrite the URL to display the subdirectory as the main directory for all links RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com RewriteCond %{REQUEST_URI} !^/public Rewriterule ^(.*)$ /public/$1 [L] 

This works fine and redirects everything correctly. However, I also want to rewrite some dynamic pages, which are also in the "public" subfolder, but I am having trouble getting any of the files I have rewritten, which I found work with the above rule.

For example, with the above subdirectory, rewrite the rule by going to the URL, for example:

 http://www.mysite.com/item.php?id=1&name=item_name 

... should be rewritten to something like:

 http://www.mysite.com/items/item_name 

Thoughts?

+1
php regex friendly-url .htaccess mod-rewrite
source share
1 answer
 Options +FollowSymlinks -MultiViews RewriteEngine on RewriteBase / #rewrite the URL to display the subdirectory as the main directory for all links RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC] Rewriterule ^(?!public/|prints/)(.*)$ /public/$1 [L,NC] RewriteCond %{THE_REQUEST} /*item\.php\?id=([^&]*)&name=([^&]*)\s [NC] Rewriterule ^ /prints/%1/%2? [R,L,NC] Rewriterule ^prints/([^/]*)/([^/]*)/?$ public/item.php?id=$1&name=$2 [L,NC,QSA] 

PS: Make sure your static text includes both css, js, images, etc., has an absolute path, not a relative one.

+3
source share

All Articles