Hi,
I'm working on a site that has both EN and ES versions of pages. The rewrite rules are configured at the dispatcher and I need 2 rewrite rules to be executed for a group of RewriteConds.
Below is a sample htaccess file which works fine
RewriteCond %{REQUEST_URI} !^/cond1
RewriteCond %{REQUEST_URI} !^/cond2
RewriteCond %{REQUEST_URI} !^/cond3
RewriteRule ^/(.*)$ /content/appName/us/en/home/$1.html [PT,L]
I would like to have the ES version of the rule added to this same condition.
RewriteCond %{REQUEST_URI} !^/cond1
RewriteCond %{REQUEST_URI} !^/cond2
RewriteCond %{REQUEST_URI} !^/cond3
RewriteRule ^/es/(.*)$ /content/appName/us/es/home/$1.html [PT,L]
RewriteRule ^/(.*)$ /content/appName/us/en/home/$1.html [PT,L]
Looks like we cannot have RewriteCond have multiple rules unless we want to negate and use Skip Rules as below but this doesn't work for me
RewriteCond %{REQUEST_URI} !^/cond1
RewriteCond %{REQUEST_URI} !^/cond2
RewriteCond %{REQUEST_URI} !^/cond3
RewriteRule .? - [S=2]
RewriteRule ^/es/(.*)$ /content/appName/us/es/home/$1.html [PT,L]
RewriteRule ^/(.*)$ /content/appName/us/en/home/$1.html [PT,L]
Repeating the condition twice as below seems to work fine but I'm looking for the best solution without having to repeat the same thing.
RewriteCond %{REQUEST_URI} !^/cond1
RewriteCond %{REQUEST_URI} !^/cond2
RewriteCond %{REQUEST_URI} !^/cond3
RewriteRule ^/(.*)$ /content/appName/us/en/home/$1.html [PT,L]
RewriteCond %{REQUEST_URI} !^/cond1
RewriteCond %{REQUEST_URI} !^/cond2
RewriteCond %{REQUEST_URI} !^/cond3
RewriteRule ^/es/(.*)$ /content/appName/us/es/home/$1.html [PT,L]
Can somebody assist on what would be the best way to handle this? Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @manasabojja7 ,
If you have two language sites and you want to go ahead with your approach then I'd suggest you write rewrite rule first for root path then you can write for other.
Below is just a sample rule, please tweak it based on your project
# handle root path.
RewriteRule ^/$ /content/ab/en.html [PT,L]
RewriteRule ^/en.html$ / [R=302,L,NC]
RewriteRule ^/es.html$ / [R=302,L,NC]
RewriteRule ^/content/ab/es.html$ /content/ab/es.html [R=302,L,NC]
Then in subsequent rule set, lets say for image:
For es:-
RewriteCond %{REQUEST_URI} !^/content/dam
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} ^/es
RewriteRule ^/(.*)$ /content/ab/$1 [PT,L]
For content path
# handle valid content paths for ES
RewriteCond %{REQUEST_URI} ^/es
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/saml_login
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} .html
RewriteRule ^/(.*)$ /content/ab/$1 [PT,L]
Thanks
Tarun
@manasabojja7 try using End flag instead of L.
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_end
Hi @manasabojja7 ,
If you have two language sites and you want to go ahead with your approach then I'd suggest you write rewrite rule first for root path then you can write for other.
Below is just a sample rule, please tweak it based on your project
# handle root path.
RewriteRule ^/$ /content/ab/en.html [PT,L]
RewriteRule ^/en.html$ / [R=302,L,NC]
RewriteRule ^/es.html$ / [R=302,L,NC]
RewriteRule ^/content/ab/es.html$ /content/ab/es.html [R=302,L,NC]
Then in subsequent rule set, lets say for image:
For es:-
RewriteCond %{REQUEST_URI} !^/content/dam
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} ^/es
RewriteRule ^/(.*)$ /content/ab/$1 [PT,L]
For content path
# handle valid content paths for ES
RewriteCond %{REQUEST_URI} ^/es
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/saml_login
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} .html
RewriteRule ^/(.*)$ /content/ab/$1 [PT,L]
Thanks
Tarun
A workaround could be to put the RewriteRule inside a IF block. https://httpd.apache.org/docs/2.4/expr.html#examples
@manasabojja7 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies