Reputation: 1
I have read, researched and tested more iterations than I would like to admit. Honestly, I am stumped. This should be simple . . .
All internal navigation in this site is via calls to pages.php, with two query strings, one for the page to display and one for the language.
For a simple example:
<a href="pages.php?mode=contact&setlang=de">Contact us</a>
I would like the browser to display the first parameter (in this case "contact" with .html appended. Hence, contact.html. Nice and clean.
I can't seem to figure out the combination of the format of the links in the HTML and the RewriteRule(s) that will accomplish this.I have tried many, many things. Too many to list here.
This is the only thing holding up the launch of this site. Help is greatly appreciated.
Upvotes: 0
Views: 64
Reputation: 987
I see two options depending on how "clean" you want the display URL:
1) Modify your href link so it points to the friendly URL, and leaves the lang value set in the original querystring param. For example:
<a href="contact.html?setlang=de">Contact us</a>
Use an internal Rewrite to substitute the mode and preserve the lang QS:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)\.html$ pages.php?mode=$1 [QSA,L]
OR
2) Modify your href link so it points to the friendly URL with the lang value set in the URI or filename itself. For example:
<a href="de/contact.html">Contact us</a>
Use an internal Rewrite to substitute both the mode and lang:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)/(.+)\.html$ pages.php?mode=$2&lang=$1 [L]
NOTE: This assumes the Rewrites are being added to your main .htaccess and you have the rewrite module enabled in your main config:
LoadModule rewrite_module modules/mod_rewrite.so
And there are no other conflicting Rewrites, Aliases, Redirects...etc.
Upvotes: 1
Reputation: 9782
This should do it:
RewriteEngine On
RewriteRule (\w+)\.html$ pages.php?mode=$1&setlang=de [L]
It will capture a string of letters, digits and underscores before the .html and rewrite it to pages.php?mode=(string)&setlang=de
You didn't mention how you want to handle the language, something like this might work:
RewriteRule (\w+)-(\w+)\.html$ pages.php?mode=$2&setlang=$1 [L]
Upvotes: 0