Reputation: 201
I have built a custom PHP, mySQL CMS. The news article links show as this:
https://www.example.com/news/post.php/?p=example-article-slug
However, i want them to show as this:
https://www.example.com/example-article-slug
The below code in the htacess file works but breaks all the other functionality in the htaccess such as the 404 and 301 redirects. Any ideas?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ news/post.php/?p=$1 [QSA,L]
Here's my full 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]
Upvotes: 0
Views: 223
Reputation: 4907
You can use this:
RewriteEngine On
RewriteRule ^([^/]*)$ /news/post.php/?p=$1 [L]
It will leave you with this URL: https://www.example.com/example-article-slug
.
Make sure you clear your cache before testing this.
Upvotes: 2