Hi, if i have pages as page1.php and page2.php, how can i have them rewrited to /page1 and /page2? I only want the selected pages to, bcz the pages use include function so i dont need that messed up. And i will also make a directory /something and add something else in it so i dont want it to find something.php Any help is highly appreciated
RewriteEngine On RewriteRule ^page1$ /page1.php [L] RewriteRule ^page2$ /page2.php [L] Code (markup): Not tested, but should work.
Cool, it works... But if i use it, i can still access page1.php and page2.php, possible if anyone access page1.php or page2.php, they are redirected to /page1 and /page2? Another thing, if i open /page1 it works, but /page1/ doesn't, any fix to this? (i tried adding a slash to the redirect, but then the page isnt reading the css file
In the mod_rewrite he provided, if the pattern didn't contain a / at the end then it won't match /page1/ , ideally you might need to do something like /? on the end meaning with or without /
Do not delete old lines, just add these lines in your .htaccess file so you pages will work with slash RewriteEngine On RewriteRule ^page1/$ /page1.php [L] RewriteRule ^page2/$ /page2.php [L] Tested and working Enjoy!!!!
Or instead of doubling the lines, just do RewriteRule ^page([0-9]+)/?$ /page$1.php [L,QSA] which would pretty much take any page#/ and send it to page#.php Also the QSA flag automatically forwards any attached querystring on the end. Basically one line to do the work of 4
well thanks for that, and i was indeed going to do that but he did say so that's why I wrote the two separate lines. However this will help others surely!
In his case he'd just need to remember the /? then which would mean may or may not have a trailing slash.
yea, i already did that but, after doing that, /page1 doesn't work, only /page1/ works, i want it to work either ways, and also want page1.php (if anyone accesses) to redirect to /page1/ or /page1
Read a couple more post and you'll see the /?$ method which tells the interpretor that it may or may not have a trailing slash.
Couldn't you just use a redirect? Redirect 301 /page1.php /page1 Redirect 301 /page2.php /page2 It seems like it might work, but then again it might make an infinite loop.
First part could be done simpler RewriteEngine On RewriteRule ^page([0-9]+)(/?)$ /page$1.php [L] Code (markup):
Hmmm.... I'll have to try this (i have a feeling it will work, but wtf if it just keeps on looping? ) I would have used that, but did you bother reading my reply on that post?
My bad. RewriteRule ^page([0-9]+)\.php$ /page$1 [L,R=301] or something like that would create an infinite loop with the first rule, so I'm afraid I'm not able to help you with that.