I would like to redirect anything that does not begin with /X, to /X, and, I'm trying to do this by using .htaccess with this content:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(?!/X)
RewriteRule ^(.*)$ /X/$1
What am I missing?
EDIT:
I've also tried:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/X
RewriteRule ^(.*)$ /X/$1 [L]
and using this tool seems like it should work, but for example www.site.com/style.css
It's now working...
Have it like this:
RewriteEngine On
RewriteCond %{THE_REQUEST} !\s/+alsiniga/X[/?\s] [NC]
RewriteRule ^ /alsiniga/X%{REQUEST_URI} [L,R=301,NE]
Related
I'm trying to add a language prefix to my pages through mod_rewrite
eg:
https://example.com/ > https://example.com/en/
and internally it need to translate to `https://example.com/?language=en
I've managed to do it for the base url, but when I try to do it with some other redirect implied, it's always end in an infinite loop.
eg:
https://example.com/product-p-22.html > https://example.com/en/product-p-22.html
and internally became `https://example.com/product_info.php?product_id=22&language=en
here is my actual config:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(en|fr)/
RewriteCond %{REQUEST_URI} .(php|html) [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} !language=
RewriteRule ^(.*)$ en/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/example
RewriteRule ^(.*)/$ index.php?language=$1&%{QUERY_STRING}
RewriteRule ^(.*)/(.*)-p-(.*).html$ product_info.php?products_id=$3&language=$1&%{QUERY_STRING}
I've tried many flags like L, END, DPI or some combination of those, but with no luck.
when I look at the debug logs, it seems to find the right url, but then restart parsing the default url:
pass through /var/www/example/product_info.php
init rewrite engine with requested uri /product-p-22.html
pass through /product-p-22.html
any though on what I'm doing wrong here?
Server version: Apache/2.4.41 (Ubuntu)
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^en [NC]
RewriteRule ^(.*)$ en/$1 [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?language=en [NC,QSA,L]
RewriteRule ^([^/]*)/([^-]*)-p-([^.]*)\.html$ product_info.php?products_id=$3&language=$1& [NC,L,QSA]
Have it this way in your site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} !\s/+(en|fr)/ [NC]
RewriteRule ^ /en%{REQUEST_URI} [NC,R=301,L]
RewriteRule ^([a-z]{2})/[^-/]+-p-([^./]+)\.html?$ product_info.php?language=$1&products_id=$2 [L,QSA]
RewriteRule ^([a-z]{2})/$ index.php?language=$1 [QSA,L]
I've been struggling with this for weeks and I can't get to the solution, I have to make a redirect in .htaccess of a multi-language website with all its pages following the same structure but with a subdomain for each language. In the following way that is valid for http as https:
domain.es/es/allpages to es.subdomain.com/allpages
domain.es/pt/allpages to pt.subdomain.com/allpages
domain.es/de/allpages to de.subdomain.com/allpages
domain.es/fr/allpages to fr.subdomain.com/allpages
domain.es/en/allpages to eu.subdomain.com/allpages
Any ideas?
I have tried the following but not sure if it is correct:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) https://es.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/pt/(.*)$
RewriteRule ^(.*) https://pt.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/fr/(.*)$
RewriteRule ^(.*) https://fr.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/de/(.*)$
RewriteRule ^(.*) https://de.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/en/(.*)$
RewriteRule ^(.*) https://eu.subdomain.com/%1 [R=301,NC]
Thanks a lot!!!!
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before you test your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.es$ [NC]
RewriteRule ^(es|pt|de|fr|en)/(.*)/?$ http://$1.subdomain.com/$2 [NE,R=301,NC,L]
In my .htaccess APACHE's file I have the following code:
#MY AWESOME WEBSITE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^myawesomewebsite.com
RewriteRule ^(.*) http://coolwebsite.com/web/this-is-a-friendly-url-version-of-my-awesome-website [P]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www.myawesomewebsite.com
RewriteRule ^(.*) http://coolwebsite.com/web/this-is-a-friendly-url-version-of-my-awesome-website [P]
Both, myawesomewebsite.com and coolwebsite.com are in my hosting linked properly, myawesomewebsite.com is an alias.
That code works fine. But IF I go to:
myawesomewebsite.com/index.php
myawesomewebsite.com/wtf.php
myawesomewebsite.com/blahblahblah
myawesomewebsite.com/whateveryouwrite
You will see the content of coolwebsite.com/index.php in all cases.
I want redir: .*myawesomewebsite.com.* to http://coolwebsite.com/web/this-is-a-friendly-url-version-of-my-awesome-website
How can I achieve this?
Thanks for reading, and please forgive my bad english.
You are using the [P] flag, which is for proxying and not what you want. Replace all your rules with only this:
RewriteCond %{HTTP_HOST} ^(?:www\.)?myawesomewebsite\.com$
RewriteRule ^ http://coolwebsite.com/web/this-is-a-friendly-url-version-of-my-awesome-website [R=301,L]
I took out the condition to only redirect if the file doesn't exist, since you didn't say you wanted it to work that way.
Let me know if I misunderstood what you're trying to acheive.
Update
Try this instead:
RewriteCond %{HTTP_HOST} (?:^|\.)myawesomewebsite\.com$
RewriteCond %{REQUEST_URI} !=/web/this-is-a-friendly-url-version-of-my-awesome-website
RewriteCond %{REQUEST_URI} !=/web.php
RewriteCond %{REQUEST_URI} !^/images/
RewriteRule ^ /web/this-is-a-friendly-url-version-of-my-awesome-website [L]
i have this link
http://localhost/fukhtaccess
and i want redirect the link to http://server.localhost/index.php with GET params.
this is my htaccess, but don't work and not possibile test with some error for debug (thanks apache foundation!!!)
RewriteEngine On
RewriteCond %{HTT_HOST} ^localhost$
RewriteCond %{REQUEST_URI} fukhtaccess
RewriteRule (.*) http://server.localhost/index.php [QSA,L]
You have a typo: change HTT_HOST to HTTP_HOST.
Also, your second RewriteCond just complicates things unnecessarily. Do this instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule fukhtaccess http://server.localhost/index.php [QSA,L]
better, this work fine
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteCond %{REQUEST_URI} fukhtaccess$ [NC]
RewriteRule (.*) http://server.localhost/index.php [QSA,L]
I'm trying to use .htaccess to redirect to ssl on login url in laravel.
Login url looks like: four.number.for.ip/auth/login
If I use
RewriteCond %{SERVER_NAME} login
RewriteRule .* https://%{SERVER_NAME} [R=301,L]
It doesnt work. I have tried with
%{HTTPS} !=on
and it works.
And also %{SERVER_NAME} returns ip/auth/login (i'm sure for that, as https!=on works)
I can't see why this won't work.
This should work for you. Let me know how it turns out.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Edit to give full rules. It should look something like this.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]