Forum Moderators: phranque

Message Too Old, No Replies

htaccess - Redirect from one folder to an URL with same name on URL

htaccess - insted of a folder, its a param. But the URL is the same.

         

imac

2:30 pm on Nov 25, 2011 (gmt 0)

10+ Year Member



Hello guys,

I am having a problem.
I currently have on my page a folder called "blog", something like:
www.myweb/blog/

Where i used to deal with blog stuff.

Now i have changed my web structure and i still want to maintain the URL for SEO reasons, but now i dont access to that secction throught the folder, i use the index.php with a param name called "blog".

I have inserted this in htaccess for that:
RewriteRule ^([a-zA-Z0-9_]+)/$ ?s=$1


So the URL will be like before:
www.myweb.com/blog/
And i will take "blog" as a the param called "s".

Then in index.php i do something like:
include 'blog.php'; (depending on the "s" param)

The problem is that when i try to acces to that URL it access to the folder (as it exists) and not the index with the param name.

Is there any way to fix this in htaccess?

Thanks guys!

lucy24

10:30 pm on Nov 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your RewriteRule says:

Take any request for any top-level folder, minus its index file, and rewrite (not redirect) as a request for the site's index page with the previous foldername as a parameter.

I am reasonably sure this is not what you want the Rule to do. In fact it is probably the opposite of what you want.

You need to get a firm grip on the difference between Rewrite and Redirect.

Then, you need to write two separate rules: one to Redirect users to the URL you want them to see, and one to Rewrite those same users to the place where your content really lives. The Redirect is only for external outdated links, and must therefore include a Condition looking at THE_REQUEST; your internal links should reflect the new URL.

"Search" is one of the teeny little links at the top of this page. Look for Rewrite + Redirect, and constrain your search to the past week or month. That should get you several hundred threads to study. Or just pull up the first page of threads in this Forum.