我在我的网站中使用 url 重写。
我有这些网址:
有效
example.com/_new/app/planning
example.com/_new/app/user_info
无效 (404)
example.com/_new/try
example.com/_new/features
这是我的规则:
RewriteEngine On
# Removing extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# example.com/app/[module]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)$ app.php?param1=$1 [L]
# example.com/app/[module]/[action]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)/([^/]+)$ app.php?param1=$1¶m2=$2 [L]
# example.com/app/[module]/[action]/[type]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)/([^/]+)/([^/]+)$ app.php?param1=$1¶m2=$2¶m3=$3 [L]
# example.com/app/[module]/[action]/[type]/[id]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ app.php?param1=$1¶m2=$2¶m3=$3¶m4=$4 [L]
这里的文件结构:
/_new/
/_new/try.php
/_new/login.php
/_new/app.php
的try.php
和index.php
应显示为example.com/try
或example.com/login
。
该app.php
载荷从另一个目录模块。这个应该是:example.com/app/module_name
。
有什么问题 ?
谢谢。
在 中htaccess
,基本 URLexample.com
将在匹配中被跳过,而在您的文件中,第一个正则表达式([^\.]+)
将匹配/_new/try
并尝试将您重定向到一个/_new/try.php
不存在的文件,因此是 404。
在尝试使用 URL 之前,请确保测试您的正则表达式,您可以从https://regex101.com/进行测试。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句