Cuurent网址是 https://www.website.com/colleges.php?id=NR%20School%20of%20Architecture
我们想将此网址更改为SEO友好网址,如, https://www.website.com/colleges/NR-School-of-Architecture
我们使用了这个htaccess,但只删除了空格
RewriteEngine On
RewriteBase /
# replace all space by hyphen
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ %1-%2 [L,NE,R=302]
我们使用此htaccess删除.php,它工作并且.php在整个网站中被删除。
但是我们这样得到了一个像这样的自由网址, 学院/ NR-校的架构
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
请使用htaccess
帮助我们实现seo友好网址提前致谢。
答案 0 :(得分:0)
在确认已启用mod-rewrite后,您需要在放置在站点文档根位置的.htaccess文件中定义重写规则
RewriteEngine On
RewriteBase /
RewriteRule ^home /index.php