2017-02-27 85 views
0

我在创建搜索引擎友好的URL获取URL不能重写规则

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/.]+)/?$ /pages/story.$1.php [L] 

.htaccess文件重写规则,以便mydomain.com/pages/story.books.php将显示为mydomain.com/books

有什么办法在URL中传递额外的参数吗?

mydomain.com/books?history

但是,附加的参数是可选的,并且可能不是完全存在。

我试过以下,但它打破了我的规则:

RewriteRule ^([^/.]+)/([a-zA-Z0-9-]+)/?$ /pages/story.$1.php?info=$2 [L] 

我缺少什么?

+0

你可以用X = 112&Y = DDDD – 2017-02-27 22:47:54

+0

只需添加变量发送'QSA'标志,使其'重写规则^([^ /] +)/ $ /pages/story.$1.php [ L,QSA]' – anubhava

回答

0
RewriteRule ^([A-za-z0-9_-]+)/?$ index.php?username=$1 [NC,L] # domain.com/post/name 
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9]+)/?$ profil.php?id=$1&menu=$2 [NC,L] # domain.com/cat/post/id 
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9]+)/([0-9]+)/?$ profil.php?id=$1&menu=$2&page=$3 [NC,L]