RewriteRule后如何在地址栏中保留原始URL

RewriteRule后如何在地址栏中保留原始URL

本文介绍了RewriteRule后如何在地址栏中保留原始URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的.htaccess文件.

This is my .htaccess file.

Options +FollowSymLinks

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

RewriteEngine on

RewriteRule ^index.html             /? [R=301,L]
RewriteRule ^listen/$               /console [R=301,L]


# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

重写规则

RewriteRule ^listen/$               /console [R=301,L]

将网址www.mydomain.co.uk/listen重定向到www.mydomain.co.uk/console

此重定向工作正常,但我希望地址栏中的可见URL能够读取...

This redirect works fine, but I want the visable url in the address bar to read...

www.mydomain.co.uk/listen

任何帮助,我们将不胜感激.谢谢

Any help greatly appreciated. Thanks

推荐答案

具有这种方式:

Options +FollowSymLinks
RewriteEngine on

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^index\.html$ /? [R=301,L,NC]

RewriteRule ^listen/$ /console/ [NC,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

清除浏览器缓存后对其进行测试.

Test it after clearing your browser cache.

这篇关于RewriteRule后如何在地址栏中保留原始URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:08