Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the URL www.example.com/blogs/<displaynamehere> to show what is in the directory at www.example.com/blogs/blog.php$display=<displaynamehere>

So thanks to the people who helped me here I know I need to use mod_rewrite
How to make parameters look more attractive

The contents of my .htaccess is as follows. The first is a redirect generated by my hosting, the second is my attempt at the mod_rewrite which is not working.

# DO NOT REMOVE THIS LINE AND THE LINES BELOW REDIRECTID:Hjz5g3
RewriteEngine on
RewriteCond %{HTTP_HOST} ^joelhoskin.net76.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.joelhoskin.net76.net$
RewriteRule ^$ http://www.joelhoskin.net76.net/flexdevs [R=301,L]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE Hjz5g3:REDIRECTID

RewriteEngine On
RewriteCond %{HTTP_HOST} ^joelhoskin.net76.net/blogs/(.*)$ [OR]
RewriteCond %{HTTP_HOST} ^www.joelhoskin.net76.net/blogs/(.*)$
RewriteRule ^$ http://www.joelhoskin.net76.net/blogs/blog.php?display=$1 [L]
share|improve this question
up vote 0 down vote accepted

The host shouldn't contain anything after the slash. So you want:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^joelhoskin.net76.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.joelhoskin.net76.net$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blogs\/(.*)$ http://www.joelhoskin.net76.net/blogs/blog.php?display=$1 [L]
share|improve this answer
    
Thanks for your help it worked a treat it did re-direct however chrome gave me this error Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects. Firefox throws "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." – Joel Jul 26 '11 at 12:30
    
Actually it seems to have that error on the enter /blogs directory – Joel Jul 26 '11 at 12:36
    
joelhoskin.net76.net/blogs/blog.php?display=blog.php Every page just redirects here, however I have a redirect in the blog.php that if the display doesnt exist it redirects back to the blogs/index.php and since that page redirects to the previous one its caught in a loop – Joel Jul 26 '11 at 12:41
1  
@paulmorriss There is no need to escape slash / character at all. – LazyOne Jul 26 '11 at 12:50
1  
By specifying an absolute URL (protocol + domain) in the RewriteRule substitution, it will implicitly trigger an external redirect (so the URL will change) even though the R flag is not present. For an internal rewrite the substitution should simply be blogs/blog.php?display=$1. – w3dk Oct 31 '15 at 23:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.