小编Pol*_*a18的帖子

Apache - 需要将 /contact/ 重写为 /contact.php

使用.htaccess之前的问题,我对其进行了编辑以添加重写规则以重写/contact/to/contact.php/xyz/contact/to /contact.php?lang=xyz。当第二个工作时,第一个仍然寻找不存在的实际目录,返回404代码。两个重定向到漂亮的 URL 变体都按预期工作。这是我的.htaccess设置:

# No directory listing, no multi views, follow symlinks
Options -Indexes -MultiViews +FollowSymLinks

# Redirects and rewrites allowed
RewriteEngine on

# ...

# Redirect direct requests for "contact.php?lang=xyz" to "/xyz/contact/"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2,3})$
RewriteRule ^contact\.php$ /%1/contact/? [R=301,L]

# Redirect direct request for "contact.php" to "/contact/"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^contact\.php$ /contact/? [R=301,L]

# Internally rewrite "/xyz/contact/" to "/contact.php?lang=xyz" …
Run Code Online (Sandbox Code Playgroud)

mod-rewrite .htaccess apache-2.4

4
推荐指数
1
解决办法
1252
查看次数

标签 统计

.htaccess ×1

apache-2.4 ×1

mod-rewrite ×1