I'm trying to set up my .htaccess
file. How would I go about开发者_JS百科 getting this result:
Request: domain.com/page/page
Rewrite to: domain.com/index.php?p=page/page
I've tried:
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
with no luck.
Okay I worked it out. I needed two rules:
RewriteRule ^([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9_\\s-]+)/([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1/$2
My php script didn't like it because with just
RewriteRule ^([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1
domain.com/no1/ would translate into domain.com/index.php?p=no1/ <--- didn't understand the end slash
Only problem with this solution is it only goes two virtual dirs deep but as that's all I need it's fine. This is my first time using .htaccess so I'm sorry for my lack of understanding.
Try this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^(?!index\.php)(.*)$ /index.php?p=$1 [L,NC,QSA]
Negative lookahead will avoid infinite looping here.
精彩评论