我无法将自己的URL重写为SEO友好的URL。我在这里和其他地方尝试了很多片段,但似乎都没有用-我不确定为什么!
当我将其用于域和IP规范化时,重写引擎一定能正常工作并启用。只是无法使用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>
我以前在另一个项目中遇到过这些问题,但从未真正解决过这些问题,因此最好找到一个可行的解决方案。
注意:我已经检查了Stack Overflow上的许多其他“解决方案”-我尝试过的所有解决方案都没有奏效。
尝试以下规则,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/([^/]+)$ profile.php?user=$1 [L]
上面我从profile.php中删除了一个前导斜线,这可能是一个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句