I want to change URL displayed in browser depend of folder
www.domain.com/site1
www.domain.com/site2
I need to show
www.domain.com/site1 -> www.aaa.com
www.domain.com/site2 -> www.bbb.com
How it's possible to do that?
Many thanks
Use this code
RewriteEngine on
RewriteCond %{HTTP_HOST} www.domain.com/site1
RewriteRule ^(.*)$ http://www.aaa.com$1 [L]
Related
I want to redirect the /page/2 style pagination pages to ?page=2 and to the others in this format.
So any urls like these:
https://www.example.com/dogs/page/2
https://www.example.com/horses/videos/page/3
https://www.example.com/cats/photos/page/4
will be redirected to:
https://www.example.com/dogs?page=2
https://www.example.com/horses/videos?page=3
https://www.example.com/cats/photos?page=4
Could you please try following, written based on your shown samples. Please make sure you clear your browser cache before testing these URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(.*?)/([^/]*)/([^/]*)/?$
RewriteRule ^(.*)$ %1?%2=%3 [L]
You may use this rule:
RewriteEngine On
RewriteRule ^(.+)/page/(\d+)/?$ $1?page=$2 [L,NC,QSA]
I managed to get this Rewriterule to work :
RewriteRule ^([a-z-]+)\/?$ $1.php [NC]
that basically rewrites my_project/admin.php -> my_project/admin & my_project/login-admin.php -> my_project/login-admin
The problem is that my second rule is for my page that adds users into my database using a table parameter isn't working, what i need to show on the URL is my file name "add-client" and the table parameter "tb1", it should look like this
my_project/add-client.php?tb=tb1 -> my_project/add-client/tb1
i tried this, but it doesn't work:
RewriteRule ^([a-z-]+)\/?$ $1.php?tb=$2 [NC]
Does the fact that those two rules are in the same htaccess file makes any problem? please help, thank you in advance.
Here is how you can set htacces.
my_project/admin.php -> my_project/admin AND my_project/login-admin.php -> my_project/login-admin
RewriteRule ^my_project/admin$ my_project/admin.php [L,NC]
my_project/add-client.php?table=table1 -> my_project/add-client/table1
RewriteRule ^my_project/([a-zA-Z0-9_-]+)$ yourfile.php?tb=$1 [L,NC]
I want to make this url redirect using .htaccess (linux/apache) ..
I want to keep "as is" all calls for www sub domain like this
www.example.com/index.php
www.example.com/test.php?id=1&name=a
www.example.com/whatever.php?whateverurl=xxxx
but I want to redirect all wild card urls like this with the sub domain as extra variable to current unlimited-whatever url variables
for example
xxx.example.com -> example.com/?subdomain=xxx
yyy.example.com/index.php -> example.com/index.php?subdomain=yyy
whatever.example.com/test.php?var=1 -> example.com/test.php?subdomain=whatever&var=1
whatever.example.com/whatever.php?var1=1&var2=2 -> example.com/whatever.php?subdomain=whatever&var1=1&var2=2
is this possible?
Thank you
Once you set up your Wildcard DNS Record you should make your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule ^(.*)\??(.*)?$ $1?host=%{HTTP_HOST}&%{QUERY_STRING} [L] [L]
This rule works, although it will provide you the whole host, rather than just the subdomain, which you'll have to parse in your PHP.
Thank you for your answer
this rule seems to works
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^/?(.*)$ $1?subdomain=%1 [QSA,L,NE]
for the time without problems ...
thanks again for your answer
Best regards
Vangelis
After changing my site structure I need help redirecting links. How can I redirect all links that don't have a .html extension to the same link but with .html extension? The only link I don't want redirected is /admin.
Example: google.com/hey -> google.com/hey.html
google.com/hey.html -> do nothing
google.com/admin -> do nothing
Thanks in advance
Ohh sorry, try this man. The error was in the rewritecond.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.html$
RewriteRule (.+) $1.html [L]
If these links are onpage links an non external ones a .htaccess solution could help.
First be aware to use htaccess only if you do not have access to the server config, because htaccess slows the server down. Everything configured there can be configured as well in the .httpdconf
Sorry, I have not tested the code posted bellow but tell me if it has worked.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} > \.html
RewriteRule (.+) $1.html [L]
I have a website here on my localhost :
http://localhost/mysite/www/index.php
I have some RewriteRules to redirect like this :
http://localhost/mysite/www/index.php?page=home
-> http://localhost/mysite/www/home.html
And now, I want to do a redirection like this :
http://localhost/mysite/www/
-> http://localhost/mysite/www/home.html
I have an environment variable named REWRITE_BASE containing /mysite/www/. So what I thought to do was to compare {REQUEST_URI} to %{ENV:REWRITE_BASE} ... like this:
RewriteCond {REQUEST_URI} =%{ENV:REWRITE_BASE}
RewriteRule . %{ENV:REWRITE_BASE}home\.html [R=301,L]
But it don't works well.
To help you understand what I want to do, here is the working code in PHP to do what I want:
$rewriteBase = getenv('REWRITE_BASE');
if ($rewriteBase === $_SERVER['REQUEST_URI'])
header('Location: '.$rewriteBase.'home.html');
Thanks for help.
Okay... so, as I can't use a variable for my comparison, here is the way that I made it works :
# Redirect domain.tld/ to domain.tld/home.html
RewriteCond %{REQUEST_URI} =/www/ [OR]
RewriteCond %{REQUEST_URI} =/mysite/www/
RewriteRule ^(.*)$ %{REQUEST_URI}home\.html [R=301,L]
# RewriteBase equivalent - Production environment
RewriteRule . - [E=REWRITE_BASE:/www/]
# RewriteBase equivalent - Development environment
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITE_BASE:/mysite/www/,E=DEVELOPMENT_ENV:1]
# Website rewritings
RewriteRule ^([^/]*)(?:/([^/]*))?\.html$ %{ENV:REWRITE_BASE}index\.php?page=$1&view=$2 [QSA,L]
Now it's alright. Thanks for your answers! ;)
What you want to do won't work, because mod_rewrite doesn't expand any variables present in its test patterns. Therefore, when you do something like this...
RewriteCond %{REQUEST_URI} =%{ENV:REWRITE_BASE}
...What you're actually doing is comparing the value of %{REQUEST_URI} to the string "%{ENV:REWRITE_BASE}", instead of the value "/mysite/www/" like you wanted. Is there a reason that you can't specify the value directly in your RewriteCond or simply move the rules so that they're relative to the /mysite/www/ directory to begin with?
There might be another way to approach the problem, but unfortunately (and for some good reasons) you cannot perform that kind of comparison using mod_rewrite.