- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
hi,
I found here in snippets
RewriteRule ^about$ about.php [L]
will make
example.com/about.php
example.com/about
question is, how to make this default for ALL pages having .php
could anyone help here, point me to a tutorial or some snippet?
Try with
RewriteRule (.+) $1.php [L]
It will add a .php to any url you write in.
As you can see, $1 is the variable for the matched regular expression you have in .+, which will match ANY character 1 or more times.
I’m sorry, but the snippet you posted will ADD a .php to the url so the webserver can retrieve the correct .php file, and my snippet does just that, but for every request.
To do the other way around you will need the following:
RewriteRule ^(.+)(.php)$ $1 [L]
Doing this, for a request ending with php, the “.php” part will get removed before sending the page to the user.
You can achieve this
example.com/about/
example.com/team/
example.com/contact/
by using the following method:
Hide File Extensions
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/$ $1.php
Add 301 redirects to new extensionless file
RewriteCond %{THE_REQUEST} ^[A-Z]+ /([^/]+/)*[^.]+.php(?[^ ]*)? HTTP/
RewriteRule ^(([^/]+/)*[^.]+).php$ http://www.example.com/yourdirectory/$1 [R=301,L]
Add the trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://www.example.com/yourdirectory/$1/ [R=301,L]
@krysak4ever thanx for the mention buddy :)