Jump to content

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

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.