Forum Moderators: phranque
/product1.php
/product2.php
or...
/product1/
/product2/
I suspect it's the first group, in which case, the code above is 'backwards' -- We usually want to rewrite from URLs that don't exist (or that we wish to replace) to URL-paths that do exist (or invoke scripts).
The [PT] flag has a specific function not explicitly needed here; It switches mod_rewrite from its default URL-to-filename mode to URL-to-URL mode, so that mod_rewrite's output can be processed by other URL-to-filename translation modules that execute subsequently.
Jim
/product1.php should effectively land the person on /product1/product1.php? or /product1/ by itself?
If you want to change the URL that's in the browser, you're going to have to do a redirect. If you want the URL to look like /product1.php, but actually be /product1/index.php (or whatever you define in the second arg of the Rewrite rule) then I believe my rule works.
I did a simple test on my apache instance and it seems to do this
/product1.php > /product1/index.html (but browser keeps /product1.php)
using this rule
RewriteRule ^/([a-z0-9]+)\.php /$1/index.html [PT]
PT is not what you use if you want to change what the URL is in the browser though. If you want to do that, there's no way getting around the redirect option.
A useful thing to turn on for debugging (but it adds logs like crazy) is the
RewriteLog /wherever/you/want/rewrite.log
RewriteLevel 5
hope that helps
As Google PR is an important factor for many link partners I want the structure to appear as the previous to maintain PRs as the new files obviously have a PR of 0.
I have tried rewriting the script a few times but it is very messy once I make changes as the script has a very large feature set.
I want the browser to show
/Other-Providers/
when loading Other-Providers.php
If the naming is consistent, then we can probably get away with a reverse of our above rule
RewriteRule ^/([a-z0-9]+)/.* /$1.php [PT,L]
be warned, though, this rule is going to pass through ANY url that has /blahblahblah/ to effectively be /blahblahblah.php
If you have a small # of directories to do this for (doubtful), you might want to add a rewriterule for each one. kludgy, but it will be a finite rule. In general, any rewriterule is a dangerous one since it is going to affect every single incoming request, and we can't always replicate the situation for the traffic coming in.
Good luck.
RewriteCond ^/thefolderyouwanttocheck/
RewriteRule
Whatever Rewriterule follows the RewriteCond you set is the one that will be triggered, should the RewriteCond be valid
[httpd.apache.org...]
Therefore, in order to maximize performance, it is the RewriteRule pattern which should be most selective, so as to avoid processing the RewriteConds except when necessary.
Jim
Your code should look like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)/ /$1.php [PT,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Also, whenever you get an error, look at both your server error log and your server access log. They will often give information that will allow you to quickly determine the problem.
Jim