1

So I have a folder named pages which includes the pages for my site, when opening one of these files the url reads -

zebrafishweb/pages/contact

I would like it to just read

zebrafishweb/contact

I already have this htaccess file to remove any .php .html extensions which i would also like to carry on using. I don't have a clue how to write these htaccess files just copied it from the web and tailored it to me!

 RewriteEngine on

 RewriteRule ^(themes|order-now|submissions|faq|contact)$ $1.php [NC,L]
 RewriteRule ^(home|faq)$ $1.html [NC,L]

1 Answer 1

1
  1. You already have a .htaccess inside /pages/ subdirectory with some rules for .php and .html extensions
  2. You want a redirect to shorter URI /contact instead of /pages/contact

With those you can have your rules like this:

site root .htaccess:

RewriteEngine On

RewriteRule ^contact/?$ pages/contact.php [L,NC]

pages/.htaccess:

RewriteEngine On

# redirect to shorter URL
RewriteCond %{THE_REQUEST} /pages(/contact)[?\s]
RewriteRule ^ %1 [L,R=302]

# add .php to these files
RewriteRule ^(themes|order-now|submissions|faq|contact)/?$ $1.php [NC,L]

# add .html to these files
RewriteRule ^(home|faq)/?$ $1.html [NC,L]
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you sir for sharing nice answer. Just want to check here by site root .htaccess you mean htaccess(new one) should be along side with pages folder? Thank you.
Yes site root directory should be one level above pages directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.