2
votes

I am trying to do some URL rewriting with htaccess but struggling a bit. Basically I am trying to use the following URL:

http://www.example.com/[pagename]

and display the contents of the file which sits at:

http://www.example.com/site/[pagename].php

I have searched online but can't find something that works.

My htaccess file looks like this:

Redirect 301 /page http://www.example.com
Redirect 301 /privacy http://www.example.com/site/privacy.php
Redirect 301 /EULA http://www.example.com/site/EULA.php
Redirect 301 /etiquette http://www.example.com/site/etiquette.php

ErrorDocument 404 /site/404.php
# Rewrite non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

The redirects at the top won't be needed once I figure out my problem.

Any help?

1
can you try RewriteRule ^(.*)$ http://www.example.com/site/$1\.php [R=301,L] ? - Shashank Kadne

1 Answers

2
votes

This should be your complete .htaccess:

Options +FollowSymLinks -MultiViews

ErrorDocument 404 /site/404.php

Redirect 301 /page http://www.example.com
Redirect 301 /privacy http://www.example.com/site/privacy.php
Redirect 301 /EULA http://www.example.com/site/EULA.php
Redirect 301 /etiquette http://www.example.com/site/etiquette.php

# Rewrite non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/site/$1.php -f
RewriteRule ^(.*)$ /site/$1.php [L]