htaccess'漂亮的网址'不工作

时间:2017-02-10 10:43:14

标签: php apache .htaccess mod-rewrite

我无法将我的网址重写为SEO友好的网址。我从这里和其他地方尝试了很多片段,但是它们似乎都没有用 - 我不确定为什么!

重写引擎肯定正在工作并启用,因为我将其用于域和IP canocialisation。只是无法使用URL重写。

我想要读取网址; xxx.com/profile/Name ,而不是 xxx.com/profile.php?user=Name

我目前正在尝试的代码是

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

我的完整htaccess代码是

ErrorDocument 404 http://localhost/CE/?404=1&page=1

<IfModule mod_headers.c>
# Set XSS Protection header
Header set X-XSS-Protection "1; mode=block"
</IfModule>

# allow all except those indicated here
<Files *>
order allow,deny
allow from all
deny from 188.143.232.32
deny from 188.143.232.27
deny from 188.143.234.155
deny from 188.143.*.*
</Files>

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

# Canocial IP
RewriteCond %{HTTP_HOST} ^217\.160\.0\.148 [nc,or]

# Canocial URL
RewriteCond %{HTTP_HOST} ^www\.xxx\.com$
RewriteRule ^/?$ "http\:\/\/xxx\.com\/" [R=301,L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

<IfModule mod_expires.c>
    ExpiresActive on

    ExpiresByType image/jpg "access plus 3 days"
    ExpiresByType image/jpeg "access plus 3 days"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
</IfModule>

我之前在另一个项目上遇到过这个问题并且从未真正解决过它们,所以找到一个有效的解决方案会很好。

注意:我已经检查过许多其他解决方案&#39;在Stack Overflow上 - 没有我尝试过的。

1 个答案:

答案 0 :(得分:2)

尝试下面的规则,

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

上面我从profile.php中删除了一个前导斜杠,这可能是一个问题。

相关问题