问题描述
我有一个参数中的URL,我想做成海基会网址:
想:
http://map.tautktiv.com/street.php?address=abc
成为:
http://map.tautktiv.com/street/address/abc
或
http://map.tautktiv.com/address/abc
曾尝试一些在线工具来生成一个的.htaccess
规则,但他们都没有对URL的效果,的.htaccess
文件是有效(试图把一些胡言乱语的,并得到了错误500)
这是我试过的规则:
1。
选项+了FollowSymLinks
RewriteEngine叙述上
重写规则^地址 - ([^ - ] *)$ /street.php?address=$1 [L]
重写规则街道/地址/(.*)street.php?地址= $ 1
2。
选项+了FollowSymLinks
RewriteEngine叙述上
重写规则/address/(.*)\.php street.php?地址= $ 1
3。
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#添加任何其他特殊情况需要在这里
重写规则^ /([0-9] +) - $ /street.php?address=$1 [L](*)。
重写规则/(.*)/(.*)/$ street.php?地址= $ 1
该网站是一个子域哪些文件驻留在一个共享的主机GoDaddy的服务器一个子目录,也试图在这些规则适用于的.htaccess
目录它上面,同样的结果。
也是这种尝试按照以下建议
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /
重写规则^街道/地址/(.*)$ street.php?地址= $ 1 [R = 301,L]
重写规则^地址/(.*)$ street.php?地址= $ 1 [R = 301,L]
重写规则^街道/地址/(.*)$ street.php?地址= $ 1 [R = 301,L]
同样的结果,没有任何反应。
试图直接从主域,但相同的结果要到页面:
http://tautktiv.com/map/streets/street.php?address=abc
第一条规则将重定向你的丑陋的URL到pretty的URL。第二条规则将在内部重定向回去,这样用户将不会看到丑陋的URL。
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
#内部前进/街道/地址/ ABC到/street.php?address=abc
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^街道/地址/(.*)/?$ /street.php?address=$1 [NC,L]
#内部前进/地址/ ABC到/street.php?address=abc
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^地址/(.*)/?$ /street.php?address=$1 [NC,L]
如果您确认该规则被按预期工作,那么你可以把它从302改为301,你不希望使用301,直到你知道规则是按预期工作。
的的.htaccess
应该去里面的文件夹,其中 street.php
的位置。
HTTP是美国ASCII让你的语言会失败,它会重定向到这样的事情:
您最好的选择这里是改变的链接,使用 /街道/地址/字
,而不是直接在php文件。
这样,您就不需要了第一条规则,你只能使用内部重定向这会工作得很好,与此更新。
I have a URL with a parameter which I wish to make into sef URL:
want:
http://map.tautktiv.com/street.php?address=abc
to become:
http://map.tautktiv.com/street/address/abc
or
http://map.tautktiv.com/address/abc
have tried several online tools to generate a .htaccess
rule, but none of them have any effect on the URL, .htaccess
file is active (tried to put some gibberish in it and got error 500)
these are the rules I tried:
1.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^address-([^-]*)$ /street.php?address=$1 [L]
RewriteRule street/address/(.*) street.php?address=$1
2.
Options +FollowSymLinks
RewriteEngine on
RewriteRule /address/(.*)\.php street.php?address=$1
3.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# add whatever other special conditions you need here
RewriteRule ^/([0-9]+)-(.*)$ /street.php?address=$1 [L]
RewriteRule /(.*)/(.*)/$ street.php?address=$1
the site is a sub-domain which files reside in a sub directory in a shared hosting GoDaddy server, have also tried to apply these rules to the .htaccess
in the directory above it, same result.
tried also this per below suggestions
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^street/address/(.*)$ street.php?address=$1 [r=301,L]
RewriteRule ^address/(.*)$ street.php?address=$1 [r=301,L]
RewriteRule ^street/address/(.*)$ street.php?address=$1 [r=301,L]
same result, nothing happens.
tried to go directly to page from main domain but same result:
http://tautktiv.com/map/streets/street.php?address=abc
First rule will redirect your ugly URL to the pretty URL.Second rule will internally redirect it back so the user will not see the ugly URL.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Internally forward /street/address/abc to /street.php?address=abc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^street/address/(.*)/?$ /street.php?address=$1 [NC,L]
# Internally forward /address/abc to /street.php?address=abc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^address/(.*)/?$ /street.php?address=$1 [NC,L]
If you confirm the rule to be working as expected then you can change it from 302 to 301 as you do not want to use 301 until you know the rule is working as expected.
The .htaccess
should go inside the folder where street.php
is located.
HTTP is US ASCII so your language would fail, it will redirect it to something like this:
Your best bet here would be to change the links to use /street/address/word
instead of the php file directly.
This way you would not need the first rule and you can use only the internal redirect which would work just fine with this update.
这篇关于重写规则工作不正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!