Asking for your help:
I want to write a htaccess rewrite rule that will redirect all urls :
accounts.mysubdomain.com/TB/.... -->
accounts.mysubdomain.com/....
can you please help me out?
TIA
Create a .htaccess file in /TB/ directory to redirect to any directory (you can have absolute or relative paths instead of my_dir)
RewriteEngine On
RewriteRule ^TB/(.*)$ /new_dir/$1 [R=301,L]
If you are redirecting everything in the accounts.mysubdomain.com/TB/ to accounts.mysubdomain.com then use the following rule:
RewriteEngine On
RewriteRule ^TB/(.*)$ http://accounts.mysubdomain.com/$1 [R=301,L]
Related
I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.
example.com/home/hello-world.
example.com/home/tag/world.
to
example.com/hello-world
example.com/tag/world.
I'm using these code
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]
Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.
Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /example.com/
RewriteRule ^home/(.*)$ /$1 [R=301,L]
I want to create a sort of wildcard to redirect to a new url.
I replaced a specific part, that should be redirected.
All url's that contain the following /computers/notebooks-laptops/
Should be redirect to /computers/laptops/
So the following URL
https://www.example.com/computers/notebooks-laptops/product1
should become:
https://www.example.com/computers/laptops/product1
How can I achieve that?
I am assuming you are using the .htaccess in root directory, use below rule.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/computers/notebooks-laptops/(.*)
RewriteRule ^ /computers/laptops/%1 [R=301,L]
I am in the process of simplifying my URLs and have come up with a problem concerning the use of Rewrite in htaccess files.
Search engines currently list my pages in the following format
www.example.com/x/x/article_a/1159/
which is currently rewritten by the following htaccess file placed in the /x/x directory
RewriteRule walk_a/(.*)/$ /x/x/article_a.php?id=$1
This has worked fine for many years.
I want to simplify the URL to
www.example.com/article-1159-introduction
I have tried the following redirects placed in the root
RewriteRule ^x/x/article_a/(.*)/$ http://www.example.com/article-$1-introduction [R=301,NC,L]
RewriteRule ^article-(.*)-introduction$ /x/x/article_a.php?id=$1
The 301 rewrite seems to have no effect although the second rewrite command works fine.
What am I doing wrong?
Inside /x/x/.htaccess directory use this rule:
RewriteEngine On
RewriteRule ^article_a/(.*)/$ /article-$1-introduction [R=301,NC,L,NE]
Then inside root .htaccess have this rule:
RewriteEngine On
RewriteRule ^article-(.+)-introduction$ /x/x/article_a.php?id=$1 [L,QSA]
I need to redirect all traffic to http://example.com/sub1 to http://example.com/sub1/sub2/. The htaccess file lives at http://example.com/sub1
Can anyone help?
Inside /sub1/.htaccess use this rule:
RewriteEngine On
RewriteRule ^((?!sub2/).*) sub2/$1 [L,NC]
If you want full redirect (URL to change in browser) then use:
RewriteRule ^((?!sub2/).*) sub2/$1 [L,NC,NE,R=302]
My htaccess file is under "myappname" folder.
I'm trying to redirect this path;
myappname/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
To that path
myappname/views/default/tpl/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
and this is my HTACCESS rule
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/$2.$3 [L,NC]
but it's giving me HTTP 500 unless I redirect it to a PHP file like
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/index.php?a=$2.$3 [L,NC]
What is wrong with my rule? I'm very new to htaccess and there is a very big potential to I'm missing something small.
This is because your target matches the regex:
views/default/tpl/foo/bar.png
matches the regex:
^(.*)/(.*)\.(css|js|gif|jpg|png)$
So the rules just keep looping. You need to add a condition:
RewriteCond %{REQUEST_URI} !^/views/default/tpl
right above your RewriteRule.