graham23s Posted April 18, 2010 Share Posted April 18, 2010 Hi Guys, I have moved from blogs to css/html sites again, but i liked the look of the permalink structure on blogs, for example: my: /privacy-policy.php looks better as /privacy-policy/ i'm not sure what to write to make them look like the second option. any help would be appreciated thanks guys Graham Quote Link to comment Share on other sites More sharing options...
cags Posted April 18, 2010 Share Posted April 18, 2010 Just make sure all your links are the second format not the first. Then to make them actually work using something like the following in a .htaccess file. RewriteCond %{REQUEST_FILENAME } !-d RewriteCond %{REQUEST_FILENAME } !-f RewriteRule ^[a-zA-Z-]$ /$1.php [QSA] Quote Link to comment Share on other sites More sharing options...
graham23s Posted April 18, 2010 Author Share Posted April 18, 2010 Hi Cags, Thank for the reply mate i did a test on my localhost i made 2 files: index.php <a href="privacy-policy/">Privacy Policy</a> privacy-policy.php <h1>Privacy Policy Page</h1> then my .htaccess file: RewriteEngine On RewriteCond %{REQUEST_FILENAME } !-d RewriteCond %{REQUEST_FILENAME } !-f RewriteRule ^[a-zA-Z-]$ /$1.php [QSA] The strange thing is the directory doesn't show up at all, i took away the .htaccess file and found out the error: Internal Server Error was being returned i can't figure what the problem is. thanks mate Graham Quote Link to comment Share on other sites More sharing options...
cags Posted April 19, 2010 Share Posted April 19, 2010 Hi graham23s, I was obviously half asleep when I wrote that code out. The 500 server error is probably caused by the spaces after REQUEST_FILENAME, not quite sure why I put those there, just from typing out I guess. Secondly I missed a quantifier off of the Regex pattern meaning it will only match URLs that are a single character long, thirdly there's not capture group so $1 will be an empty string meaning you will be redirected to http://domain.com/.php. Try this instead... RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([a-zA-Z-]+)$ /$1.php [QSA] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.