1

I have htaccess enabled, and below is what I have written so far in.

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 

I would like to apply clean url to my pages for instance, I would like

terms.php to be rewritten as /terms-and-conditions privacy.php /privacy thanks.php / thank-you 

2 Answers 2

2

You can try with following:

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^terms-and-conditions terms.php RewriteRule ^privacy privacy.php RewriteRule ^thank-you thanks.php 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. How could I also do this in reverse such as typing /privacy.php is rewritten as /privacy.
1

This is probbly what you are looking for, though you may have to tweak it for your usage:

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([^/]+)$ $1.php [L] 

That second rule can be used without change in the real http servers host configuration or in dynamic configuration files (.htaccess style files).

Obviously the rewriting module has to be enabled.


The last example you give, thanks.php / thank-you can not be implemented this way, since "thank-you" does not equal "thanks", but I assume that is a typo. If you really need that mapping, then you have to implement a special rule just for that single URI placed before that last rule above:

RewriteRule ^/?thank-you$ thanks.php [L] 

And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.