[英]URL Rewrites not working
On my website I am trying to rewrite a long URL to a SEO friendly one. 在我的网站上,我试图将一个长URL重写为SEO友好的URL。
I've got the following code, but it doesnt seem to affect anything! 我有以下代码,但似乎没有任何影响! However if I type dgadgdfsg
into my htaccess, it throws an internal server error. 但是,如果我在htaccess中键入dgadgdfsg
,则会引发内部服务器错误。 So I am presuming it is something with Rewrite Rule. 所以我想这与重写规则有关。
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]
I have confirmed that mod_rewrite is on. 我已经确认mod_rewrite已打开。
This is the current URL 这是当前网址
http://mysite.com/missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher http://mysite.com/missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher
and this is what I want it too appear like 这就是我想要的样子
http://mysite.com/1/Liam/Gallagher http://mysite.com/1/Liam/Gallagher
Change your RewriteRule to this (slightly modified from your version) 将您的RewriteRule更改为此(从您的版本中稍作修改)
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [QSA,L]
If that doesn't work try putting a R
flag for testing purpose (which will make your browser change the original URI to: /missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher
如果这样做不起作用,请尝试放置R
标志进行测试(这将使您的浏览器将原始URI更改为: /missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher
Presuming your userID
is comprised only of digits and firstName
and lastName
are only alphanumeric. 假设您的userID
仅由数字组成,并且firstName
和lastName
仅是字母数字。
RewriteEngine On
RewriteRule /(\d+)/(\w+)/(\w+)/ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]
A more strict version that does the same thing except it sets boundaries for the beginning and the end of the evaluated regex. 一个更严格的版本除了可以为所评估的正则表达式的开头和结尾设置边界之外,还执行相同的操作。
RewriteEngine On
RewriteRule /^(\d+)\/(\w+)\/(\w+)$/ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.