Add a specific part to url using .htaccess - .htaccess

I guess it's an easy question but I hardly know syntax used in .htaccess, so I got a bit stuck. How to add '/de/' after a domain name in this case, so the result will be something like 'blablabla.com/de/blog' or 'blablabla.com/de/offices' instead of 'blablabla.com/blog' and 'blablabla.com/offices'?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
</IfModule>
I know that there should be RewriteRule after RewriteCond but, as I've said before, I'm not familiar with the syntax...

You can use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
RewriteCond %{REQUEST_URI} !^/de/ [NC]
RewriteRule ^(.*)$ /de/$1 [R,L]
</IfModule>

To access your site urls with /de segment ,you can use :
RewriteEngine On
RewriteBase /
RewriteRule ^de/(.+)$ /$1 [NC,L]

Related

I want to redirect query string URL to specific page. adparch.com/*/*pagenumber=* to adparch.com/projects

I got these URLs
https://www.adparch.com/vi/projects/common-wealth-bank/?pagenumber=2
https://www.adparch.com/projects/Technology--It/oppo?pagenumber=2
https://www.adparch.com/vi-VN/ky-thuat-cong-nghe?pagenumber=4
https://www.adparch.com/vi-VN/du-an?pagenumber=8
And They got 1 rule contains characters (?pagenumber). I want to redirect all to https://www.adparch.com/project/
I used .htaccess file for redirecting these URLs
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*$
RewriteCond %{QUERY_STRING} ^pagenumber=(.*)
RewriteRule ^(.*) /project [R=301,L]
But it seems not work.
Thank you so much
I do some cuts in your rules, please check:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} pagenumber=(.*)
RewriteRule ^(.*) /project/? [R=301,L]
</IfModule>

htaccess mod_rewrite to example.com/tut/2

I need to convert the link in my website to this way :
wwww.example.com/tut/1
from
wwww.example.com/tut.php?v=1
I tried alot of way but no thing happen
my code was this
RewriteEngine On
RewriteRule ^tut/(\d+) tut.php?v=$1 [QSA,L]
is there is any other idea or code ??
You can use this code in root .htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /tut\.php\?v=(\d+) [NC]
RewriteRule ^ /tut/%1? [R=302,L,NE]
RewriteRule ^tut/(\d+)/?$ tut.php?v=$1 [QSA,L,NC]

Rewrite article.php?title=variable to variable/

I'm trying to redirect article.php?title=variable to variable/ using .htaccess but I'm not really sure what is wrong with my code. If I go to http://site.com/variable/ it is redirecting me to http://site.com/article.php//?titlu=article.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrite urls for article
RewriteRule ^(.*)/$ article.php?titlu=$1
RewriteRule ^(.*)$ /$1/ [R]
</IfModule>
You have to capture the query string. This should work for you.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=([A-Za-z0-9_.-]*)
RewriteRule ^article.php /%1/? [R=301,L]
I'm assuming you don't want to redirect slashes... if you do you could add them to the string as well (or accept all characters).
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=(.*)
RewriteRule ^article\.php /%1/? [R=301,L]

rewrite rule for shop in lithium / apache

I have a lithium installation and all the .htaccess works fine.
I need to install OpenCart as a shopping cart in app/webroot/shop
I copied all the files and also changed the .htaccess file in the root folder of lithium installation as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule shop/(.*) /app/webroot/shop/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Still when I browse http://domain.com/shop it takes me to http://domain.com/app/webroot/shop/
With an error on page:
Exception
lithium\action\DispatchException (code 404)
Action `webroot` not found.
Please help me in solving this problem.
You may try this instead:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/app/webroot/shop/? [NC]
RewriteRule ^shop/(.*) /app/webroot/shop/$1 [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^$ /app/webroot/ [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^(.*) /app/webroot/$1 [L,NC]
</IfModule>
The problem is that your last "catch all" rule is also redirecting all requests for the shop to lithium, which you don't want.
Try this
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Rewrite all URLs that start with /shop to /app/webroot/shop
RewriteRule ^shop/.? /app/webroot/shop%{REQUEST_URI} [L]
# Rewrite all URLs that don't start with /app/webroot/shop to /app/webroot
RewriteCond %{REQUEST_URI} !^/app/webroot/shop
RewriteRule .? /app/webroot%{REQUEST_URI} [L]

.htaccess mod_rewrite RewriteRule for categories

I wanted to have http://www.mywebsite.com/cd2012/legal rather than http://www.mywebsite.com/cd2012/index.php?legal=1
i have tried
Options +FollowSymLinks
RewriteEngine on
RewriteRule guarantees/(.*) cd2012/index\.php/legal=$1 [R=301,L]
RewriteRule guarantees cd2012/index\.php/legal=$1 [R=301,L]
RewriteRule ^guarantees/$ cd2012/index\.php/legal=$1 [R=301,L]
none of them working.
If you want to rewrite, you don't want to use [R=301,L] as this basically means "tell the users browser that this document is permanently moved to this location"
You also shouldn't escape the final path, as it's not regex.
Instead, do this (according to your example):
RewriteEngine on
RewriteRule ^cd2012/?$ cd2012/index.php
RewriteRule ^cd2012/(.*) cd2012/index.php?$1=1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?$1=1 [L]
RewriteRule ^([a-zA-Z0-9]+)$ index.php?$1=1 [L]
</IfModule>
Right now this is what does the magic for me.
Try this :
RewriteEngine on
RewriteBase /
RewriteRule ^cd2012/legal$ cd2012/index.php?legal=1 [L]

Resources