【发布时间】:2021-10-12 09:20:55
【问题描述】:
这是我的 .htaccess 代码:
RewriteCond %{REQUEST_URI} !^/pages/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(/([^/]+))? pages.php?PAGE=$1&LINK=$3 [L]
*其中 $1 = 个人资料,$3 = john-smith
像 https://example.com/profile/john-smith 这样的重写效果很好,但我需要像 https://example.com/john-smith 这样的第二个重写规则,只有当第二个参数包含 约翰史密斯存在。
谢谢!
附言。 (我在 .htaccess 文件中的额外规则)
# protect files beginning with .
RewriteRule /\.(.*) - [NC,F]
# redirect HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# No root access without index.* and other security
RewriteEngine On
Options All -Indexes
RewriteBase /
DirectoryIndex index.php index.html index.htm
ErrorDocument 404 https://example.com/pages.php?PAGE=404
# Prevent upload malicious PHP files
<FilesMatch “\.(php|php\.)$”>
Order Allow,Deny
Deny from all
</FilesMatch>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
【问题讨论】:
标签: .htaccess redirect mod-rewrite url-rewriting friendly-url