2015-04-14 123 views
1

我试图和谷歌搜索几个小时了,无法找到我的问题的解决方案。我想重写:htaccess重写规则,没有斜杠

domain.com/profile.php?user=abc> domain.com/abc

我用:

RewriteRule ^(.*)/$ /profile.php?user=$1 [L] 

只在末端斜线的作品。如果我没有斜杠尝试它

RewriteRule ^(.*)$ /profile.php?user=$1 [L] 

我得到一个内部服务器错误!

完整的.htaccess

ErrorDocument 404 /errors/404.php 
ErrorDocument 500 /errors/500.php 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$ 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] 
RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L] 
RewriteRule ^(.*)/$ /profile.php?user=$1 [L] 
<IfModule mod_deflate.c> 
<FilesMatch "\.(html|php|txt|xml|js|css|svg)$"> 
SetOutputFilter DEFLATE 
</FilesMatch> 
</IfModule> 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html 

Someboy有一个想法是什么林做错了什么?

感谢, 科内尔

回答

0

随着你的第二次尝试,你会得到一个500,因为你创建一个无限循环:
^(.*)$会一次又一次地匹配profile.php?user=xxx ...这是不是这样的,当你试图用^(.*)/$因为(没有尾随斜线),这将不匹配profile.php?user=xxx

相反,你可以把它这样

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$ 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] 

RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/?$ /profile.php?user=$1 [L] 
+0

钍为你提供帮助。随着你的方式请求正常工作,但URL被改回'profile.php?user = xxx' –

+0

这很奇怪。很难知道为什么,也许是因为你可能有其他规则?你可以看看http标题,并告诉我当你尝试你的链接时发生了什么? –

+0

嗯非常奇怪,现在它的工作。 有没有办法得到这两个选项,**/**和没有**/**和结束? –