Jump to content

Confused by RewriteRule


ryanh_106

Recommended Posts

I hate rewrite rules, they always get me stumped, im hoping someone here knows how to use them effectively that can help me!

 

On my web system, all major code goes in a /portal/ folder to keep the server tidy so my structure looks like this

 

htdocs

- site1

- site2

- portal

 

I have set up exceptions for site1 and site2, however I want anything that does not start with domain.com/site1 or domain.com/site2 to be redirected to /portal/ but I do not want the user to see this. i.e. if the user types domain.com/mypage.php I want them to actually get domain.com/portal/mypage.php but i DONT want the address to be rewritten in their browser address bar

 

I had this:

RewriteRule ^(site1/.*)$ $1 [L]
RewriteRule ^(site2/.*)$ $1 [L]
RewriteRule ^(?!portal/)(.*)$ portal/$1 

But google complains about duplicated pages

domain.com/mypage.php and domain.com/portal/mypage.php (obviously these are both the same page, the first has been accessed through the rewrite rule and the second directly)

 

SO: I need a rule that first of all takes off the /portal/ if it is there (which I believe this requires the [R] flag to physically rewrite the URL) and then the rule above will add the /portal/ again but without it being visible to the user (or google)

 

This also needs to work for any domain, including subdomains as the portal hosts several different websites.

 

Please help!!

 

Thanks

Ryan

Link to comment
https://forums.phpfreaks.com/topic/150894-confused-by-rewriterule/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.