我有这些漂亮的网址:
.htaccess
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z]+)/?([0-9]*)$ index.phpcontroller=$1&action=$2&id=$3 [NC,L]是否可以定义任何其他url返回到索引?
体育课。app/ I/am//最快/人/活着->app/
我会非常感谢你的帮助!
发布于 2015-06-17 20:20:48
你可以为此制定一条新规则:
RewriteEngine On
RewriteBase /app/
RewriteRule ^([a-z]+)/([a-z]+)/?([0-9]*)$ index.php?controller=$1&action=$2&id=$3 [NC,L,QSA]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]我补充了?index.php后
发布于 2015-06-17 20:37:58
你问题的答案
是否可能只允许正确的漂亮url?
也许吧,但你必须对你的规则更加具体,才能把它们限制在这一点上。以这个例子为例。
RewriteEngine On
RewriteBase /app
#rewrite rule if starts with /app/product or /app/category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(product|category)/([a-z]+)/([0-9]*)/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]
#else redirect to homepage
RewriteRule . app/ [R=301,L]这将确保只有类似于http://example.com/app/product/1的URL才会被重写,所有其他类似于http://example.com/app/some/other/page的URL都会被重写到您的主页。
https://stackoverflow.com/questions/30901452
复制相似问题