Jump to content

mod_rewrite not always showing the "clean" URL


galvin

Recommended Posts

Just curious what would cause a URL "hidden" by mod_rewrite to SOMETIMES show in the browser?

 

For example, I have this code below in my htaccess file which rewrites www.example.com/whatever to www.example.com/play.php?url=whatever.  95% of the time, when I enter www.example.com/whatever into the browser, it stays that way in the location bar.  But every once in a while, it will change to show the "hidden" URL of www.example.com/play.php?url=whatever.

 

I'm new to mod_rewrite so maybe this is normal? Or should it never do that?  If the latter, any idea what possibly might cause it to happen?

 

<IfModule mod_rewrite.c>	
RewriteEngine On		
RewriteRule ^([^/\.]+)/?$ play.php?url=$1 [L]
</IfModule>

Link to comment
Share on other sites

Not that I remember. It's always been me copying the good URL and pasting it into a browser location bar and it changes to the bad one. Weird. Not ruling out me doing something stupid but I don't think so :). Anyway just curious if this was a known issue. Not a huge deal.

Link to comment
Share on other sites

Ok, I found that when I enter the www version of my domain, it shows the "clean" url.  But without www, it shows the "ugly" url. 

 

For example, entering "www.mydomain.com/whatever" keeps that same, clean URL in the address bar.  But if I leave off the "www" and enter just "mydomain.com/whatever", it changes to "www.mydomain.com/play.php?url=whatever"

 

So I think that means the problem has to be with my mod_rewrite rules in my htaccess files, right?

 

This is how I had them...

 

<IfModule mod_rewrite.c>	
RewriteEngine On		
RewriteRule ^([^/\.]+)/?$ play.php?url=$1 [L]
</IfModule>

#sending all non-www requests to www
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc] 

 

I then changed it by putting the www redirect rules FIRST, but it didn't help. 

 

Something's got to be missing/wrong in my rules above that is causing non-www versions to show the ugly URL. 

 

Anyone see the problem?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.