Page 1 of 1
Url rewriting
Posted: Fri Apr 23, 2010 2:20 pm
by klevis miho
How can i rewrite this url:
example.com/authors.php?name=Author-Name
into this:
example.com/Author-Name
?
Any help would be greatly accepted
Re: Url rewriting
Posted: Fri Apr 23, 2010 2:31 pm
by phu
If you're deploying behind Apache (pretty common), you can use mod_rewrite via a .htaccess file in your site's root directory.
.htaccess example from
Apache mod_rewrite Examples (search page for "Examples of mod_rewrite"):
[syntax]RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?url=$1 [L][/syntax]
The regex may not be ideal for what you're trying to do, and the rewrite itself needs very minor tweaking (you should understand what it's doing before you deploy it anyway), but the article should be a good starting point.
Re: Url rewriting
Posted: Fri Apr 23, 2010 2:35 pm
by John Cartwright
In your .htaccess, you would have something like:
[text]
RewriteEngine On
RewriteRule ^([a-zA-Z-]+)$ authors.php?name=$1[/text]
However, you probably want some kind of flag to indicate it's an authors page, otherwise, you might intercept normal urls.
Perhaps something like
[text]RewriteEngine On
RewriteRule ^author/([a-zA-Z-]+)$ authors.php?name=$1[/text]
Re: Url rewriting
Posted: Fri Apr 23, 2010 3:15 pm
by klevis miho
Oh yeah, thnx man. That's just what I needed.
Re: Url rewriting
Posted: Tue May 04, 2010 12:56 pm
by klevis miho
Another thing.
I did this:
RewriteRule ^author/([a-zA-Z-]+)$ authors.php?name=$1
but now It doesn't get the css.
Anyone knows why?
Re: Url rewriting
Posted: Sat May 08, 2010 8:25 am
by John Cartwright
Probably because your stylesheets are relative links. You need to change them to absolute paths since with your rewrite rule you are technically a directory level over the root directory.