Basic htaccess RewriteRule is ignored - .htaccess

Very simple htaccess RewriteRule query, but it does not work.
URL: http://dev.mypage.com/one/
RULE: RewriteRule ^one/$ /new/url/ [R=301,L]
No errors are displayed, just redirect does not work.
mod_rewrite module exists.
Maybe i need something more?

Try with:
RewriteEngine on
RewriteRule ^one/?$ /new/url/ [R=301,L]
Rewrite configurations are not inherited by virtual hosts. This means
that you need to have a RewriteEngine on directive for each virtual
host in which you wish to use rewrite rules.
https://httpd.apache.org/docs/current/en/mod/mod_rewrite.html#rewriteengine

Related

Forwarding a subdomain to another subdomain [duplicate]

Does anyone know a way to do a permanent redirect from a.example.com to b.example.com? I have other subdomains that need to remain as they are though. so:
first.example.com -> second.example.com
third.example.com is fine
fourth.example.com is fine
I want to do this in the <VirtualHost> block rather than an .htaccess to avoid having to redeploy again.
Any thoughts would be appreciated, thanks
Add the following RewriteRule to your VirtualHost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule ^ http://second.example.com [R=301,L]
If you wanted to redirect first.example.com/some/url to second.example.com/some/url:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule /(.*) http://second.example.com/$1 [R=301,L]
Recommend you use [R=302] whilst testing the rules to avoid problems with 301s getting cached by your browser.

Apache Server .htaccess rewrite with wildcard

Is it possible to create a rewrite code that includes a wildcard?
for example any request for:
http://example.com/something1/something2/*
would redirect to:
http://example.com/newthing
AND
will it matter where in the .htaccess file I place the rewrites?
This should work for you:
RewriteEngine On
RewriteRule ^something1/something2/(.*)$ /$1 [R=302,L]
It should change http://example.com/something1/something2/test to http://example.com/test
EDIT:
RewriteEngine On
RewriteRule ^shirts/(.*)$ /clothing.html [R=301,L]

htaccess in a shared hosting

I have a account in a shared hosting(www.1and1.com) and i want a .htaccess redirecting all the request to a different folder. (I'm trying to setup a symfony2 app)
for example, on request to:
http://www.mydomain.com/
internally respond:
http://www.mydomain.com/folder_x/folder_y
i already try this(do not work):
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/(.*)$ /folder_x/folder_y/$1 [R,L]
Thanks
Leading slash isn't matched in RewriteRule in .htaccess. Change your rule to:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder_x/folder_y/ [NC]
RewriteRule ^ /folder_x/folder_y%{REQUEST_URI} [L]
Some other improvements I have made:
Removed R flag since you wanted internal rewrite only
Added RewriteCond before rule to avoid rewriting URIs that already start with /folder_x/folder_y/

htaccess for my subdomain

I want to use mod_rewrite on my sub domain:
ads.domain.org/details.php
I need to rewrite it to:
ads.domain.org/something.html
I can do this in main domain:
RewriteEngine On
RewriteRule ^something\.html$ /details.php?id=1 [L]
But I cant do it on sub domain.
Usually the subdomain maps to a different host directory, thus you also need to add the .htaccess to that directory for it to work, also you may need to activate mod_rewrite on that directory maybe even on your virtual host level, just some pointers...
Add a RewriteCond to check HOST value:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ads\.domain\.org$ [NC]
RewriteRule ^something\.html$ /details.php?id=1 [L,QSA,NC]

Special rewrite rule for .htaccess

Having issues trying to do a proper .htaccess rewrite with the following conditions
original URL:
http://example.com/foo/bar/ANYTHING (either http or https, ANYTHING could be anything the user enters)
rewritten URL:
https://example.com/foo/bar/index.php/this/that/ANYTHING
but don't rewrite anything with index.php already in it.
I've tried several options, but I keep getting the filesystem path included in the new URL.
My attempt:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /foo/bar/
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{HTTP_HOST} !index.php
RewriteRule ^(.*)$ https://example.com/foo/bar/index.php/this/that/$1 [R=301,L]
First off, test your rules without 301, because the browser caches 301 results and makes testing much harder. Add R=301 not until you're satisfied with the rules.
See also Tips for debugging .htaccess rewrite rules.
You don't need to test for example.com, unless multiple domains are hosted in the same directory.
Testing for index.php is against REQUEST_URI, not HTTP_HOST
RewriteEngine On
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^/?foo/bar/(.*)$ https://example.com/foo/bar/index.php/this/that/$1 [R,L]

Resources