Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SEO-friendly URLs and .htaccess

Status
Not open for further replies.

gandalf458

IS-IT--Management
Jul 23, 2015
24
IT
I have a website with SEO-friendly URLs (for example, contact-us rather than contact-us.php)

I have the following commands in my .htaccess file which directs all the pages correctly.

Code:
RewriteEngine on
RewriteRule ^([-A-Za-z0-9]+)$ $1.php [PT,L]

I would also like, if possible, to direct visitors to the correct page if they inadvertently add a trailing slash.

Can it be done? I'm a numpty with regex.
 
I have a website with SEO-friendly URLs (for example, contact-us rather than contact-us.php)

The SEO bit is a something of a fallacy nowadays by the way, it has been overused so much that search engines are paying little or no attention to URL keywords other than for when looking for obvious signs of a site URL having been "SEOed" to death.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Oh but to answer the question, tack an optional '/' on to the pattern

/? (The ? means match one or zero times)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks Chris. And yes I'm never quite sure what constitutes "good" SEO. Design a site for humans.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top