我已经构建了一个自定义PHP,mySQL CMS。新闻文章链接显示如下:
https://www.example.com/news/post.php/?p=example-article-slug
但是,我希望它们显示为:
https://www.example.com/example-article-slug
htacess文件中的以下代码有效,但会破坏htaccess中的所有其他功能,例如404和301重定向。有什么想法吗?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ news/post.php/?p=$1 [QSA,L]
这是我完整的htaccess ......
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Options -Indexes
ErrorDocument 201 /404.php
ErrorDocument 401 /404.php
ErrorDocument 404 /404.php
ErrorDocument 402 /404.php
ErrorDocument 505 /404.php
ErrorDocument 500 /404.php
RewriteEngine On
RewriteBase /
Redirect 301 /oldpage.php http://www.example.com/
#Check for www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} \ /(.*/|)(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L,NE]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ news/post.php/?p=$1 [QSA,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ news/category/?cat=$1 [QSA,L]
答案 0 :(得分:2)
您可以使用:
RewriteEngine On
RewriteRule ^([^/]*)$ /news/post.php/?p=$1 [L]
它将为您留下以下网址:https://www.example.com/example-article-slug
。
确保在测试之前清除缓存。