Welcome to WebmasterWorld Guest from 3.214.184.196

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Help On URL Rewrites

rewrite

     
10:52 am on Aug 7, 2016 (gmt 0)

New User

joined:Aug 7, 2016
posts:2
votes: 0


Hi,

I made below rewriteRule to redirect URL from [url]http://example.com/sites/en/xxx[/url] to [url]http://example.com/sites/en_US/xxxx[/url]. Redirection is happening fine and In Address Bar we are getting From URL as expected.

The below rewriteRule help to manually enter the URL, but we would like to keep the same as dynamically.

For example, In the Page, if User selects any Internal Link it should appear in the Addressbar like http://example.com/sites/en/about instead of http://example.com/sites/en_US/about. We want the end-user to see en only instead en_US in the Address bar if they click any link.

RewriteEngine On # Turn on the rewriting engine
RewriteRule /en/(.*) sites/en_US/$1 [P]


Kindly please help me on this.

Thanks
Jayaram

[edited by: engine at 8:09 am (utc) on Aug 8, 2016]
[edit reason] please use example.com [/edit]

9:29 am on Aug 8, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


if User selects any Internal Link it should appear in the Addressbar like http://example.com/sites/en/about instead of http://example.com/sites/en_US/about ...


You should already be linking to the (canonical) URL you want to "appear in the address bar" in the HTML, so there shouldn't be anything extra you need to do here? (Unless you needed to "correct" URLs that had already been indexed or linked to from external sources...?)

Your existing directive (above) then internally rewrites the request to the "en_US" version, which the user does not see. But why the "P" flag? You should also consider using an anchored pattern in the RewriteRule eg. ^/sites/en/(.*) - the current pattern (/en/(.*)) looks like it could match "too much" (it's also less efficient)?


RewriteEngine On # Turn on the rewriting engine


Also, avoid using "line end" comments - Apache does not support them. (They only "appear to be supported" sometimes because Apache simply ignores everything else on the line, once it's read all the arguments. If you don't supply all the "optional" arguments to a directive (eg. the flags on a RewriteCond directive), but you have a line-end comment, then your comment becomes the argument and your code breaks horribly horribly.)