http.conf redirect example.com/foo/bar to example.com/foo?id=bar
I am trying to create a dynamic page who's contents are determined by a variable passed to it, but I want the url to be nice. Basically I want to have a single index file in the directory /foo that handles any bar. example.com/foo/bar to example.com/foo?id=bar
I have tried everything I can think of in my httpd.conf file. My latest try was:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*) /foo/index.php?id=$1 [QSA,L]
However when I try to load example.com/foo/bar the page that loads is example.com
Any help is 开发者_如何学Cmuch appreciated!
Edit: It's still loading example.com/index.php when I visit example.com/foo/bar Maybe one of my other rules is interfering?
AllowOverride none
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)\.html$ http://www.example.com/$1.php [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*)(\/?)$ /foo/index.php?id=$1 [NC,QSA,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]
.html to .php, what I'm trying to achieve, and example.com to www.example.com respectively.
I use this in my httpd.conf
<VirtualHost *:80>
DocumentRoot "/var/www/"
ServerName www.domain.com
ServerAlias www.domain.com
<Directory /var/www/>
#other directives
</Directory>
<Directory /var/www/foo/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)(\/?)$ index.php?id=$1 [NC,QSA,L]
</Directory>
</VirtualHost>
精彩评论