Php 是否可以只允许正确的漂亮url?
我有这些漂亮的网址:Php 是否可以只允许正确的漂亮url?,php,apache,.htaccess,mod-rewrite,friendly-url,Php,Apache,.htaccess,Mod Rewrite,Friendly Url,我有这些漂亮的网址: 应用程序/类别/概述 应用程序/类别/新 应用程序/类别/编辑/4 应用程序/产品/概述 应用程序/产品/新 应用程序/产品/编辑/4 .htaccess RewriteEngine On RewriteRule ^([a-z]+)/([a-z]+)/?([0-9]*)$ index.phpcontroller=$1&action=$2&id=$3 [NC,L] 是否可以定义任何其他url返回到索引 p、 e.app/i/am/the/faster/m
- 应用程序/类别/概述
- 应用程序/类别/新
- 应用程序/类别/编辑/4
- 应用程序/产品/概述
- 应用程序/产品/新
- 应用程序/产品/编辑/4
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z]+)/?([0-9]*)$ index.phpcontroller=$1&action=$2&id=$3 [NC,L]
是否可以定义任何其他url返回到索引
p、 e.app/i/am/the/faster/man/alive-->app/
非常感谢您的帮助 您可以有一个新规则:
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之后回答您的问题 是否可以只允许正确的漂亮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
将被重写,所有其他类似的http://example.com/app/some/other/page
转到您的主页 它总是以/app
开头吗?在这个代码之后,。它是我的应用程序的名称。localhost/appDon't断开web。404的反应是有原因的。