Strange 301 redirect problem - apache

I'm trying to redirect all URLs that start with "/?page=" to "/stuff/?page="
I have this in my .htaccess file:
RewriteEngine on
RedirectMatch 301 ^/?page=/(.*)$ http://www.mysite.com/stuff/$1
But it's not working.. What am I doing wrong?

Try this
RewriteRule ^/stuff/?page=$ /?page=/
Remember, you're effectively turning the right (of the space) into the left.

The directives of mod_alias (one of them is RedirectMatch) do only work on the URI path and not the query. If you want to inspect the query, use mod_rewrite instead:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=
RewriteRule ^$ /stuff/ [L,R=301]

Related

Where is my mod rewrite fail?

I have got url
ipaddr/opensys/base/
and some other similar, like
ipaddr/opensys/base/something.php?olol=yep
I want to remove from url "opensys" and display there "center", i want to see this links working:
ipaddr/center/base/
and
ipaddr/center/base/something.php?olol=yep
I did it with symlinks, but it was not good, because system is very difficult and with symlink some plugins not works, I want to do it with .htaccess only, after it all will be ok.
My htaccess is:
but links, which i want to see is not working, why?
RewriteEngine on
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [L]
RedirectMatch 301 ^/opensys/base/(.*)$ /center/base/$1
Redirect works good, but i see 404, rewrite rules is not working. Why?
You also need to handle the /center/base/ now in the .htaccess file as you must be handling opensys earlier. Something like this -
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [R=301]
RewriteRule ^/center/base/(.*)$ /index.php?args=$1 [QSA,L]
You can use this code in root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /opensys/(base/\S*)\s [NC]
RewriteRule ^ /center/%1 [R=301,L,NE]
RewriteRule ^center/(base/.*)$ opensys/$1 [L,NC]

301 .htacess redirect issue

I'm making a website, (for examples sake it will be http://www.example.com).I am trying to make it redirect http://example.com/jquery/releasenotes to http://blog.jquery.com/?s=release+notesBy using this it put a / on the end, this stops it from working, since it searches for the / aswell. I tried using http://goo.gl and converted it to http://goo.gl/WdiItL Somehow this also fails to remove the / when in redirect. However if you simply go to http://goo.gl/WdiItL it works. My .htaccess file looks like this:
Redirect 301 /jquery/releasenotes http://goo.gl/WdiItL
I have no idea how to make it not have the / on the end.Any help would be hugely appreciated!
Use this RedirectMatch rule:
RedirectMatch 301 ^/jquery/releasenotes/?$ http://goo.gl/WdiItL
Make sure to clear your browser cache before testing this
I think you have to use mod_rewrite's %{QUERY_STRING}
for example:
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteCond %{QUERY_STRING} ^(par1=1&par2=2)
RewriteRule ^$ http://alt.example.com/?%1 [R=301,L]

add alias in front of each URL mod_rewrite apache

If any likes come in the format
http://localhost/index.php/bla...
I want to convert it to http://localhost/er/index.php/bla...
I'm trying the following but it seems to be looping the url indefinitely
RewriteRule ^localhost/index/php/(.*)$ localhost/er/index.php/$1 [R=301,L]
RedirectMatch 301 ^/localhost/index.php/(.*)$ localhost/er/index.php/$1
You've got 2 different things going on, a RewriteRule (mod_rewrite) and a RedirectMatch (mod_alias). You'll only need one, but neither of those can match against the hostname (localhost). If this has to only be limited to the "localhost" host, then you need to do this:
RewriteEngine On
RewriteCond %{HTTP_HOST} localhost$ [NC]
RewriteRule ^/?index\.php/(.*)$ /er/index.php/$1 [R=301,L]
Otherwise, you can just stick with mod_alias:
Redirect 301 /index.php/ /er/index.php/
Everything after /index.php/ will automatically get appended.

How to use RewriteRule in Apache to redirect from /abc/ to /abc?

RewriteRule ^([^/\.]+)/$ $1 [R] redirects from website.com/abc/ to website.com/home/user/www/abc
How do I redirect to the correct location? (website.com/abc)
The first part of the RewriteRule is the matching part, the second the replacement expression. For full-url RewriteRules they should start with a ^/ (slash), because a path after http://exampl.com always starts with the root-slash. To redirect http://example.com/abc/ to http://example.com/abc (remove the trailing slash) you can do this:
RewriteEngine On
RewriteRule ^/([^/]+/$ /$1 [R]
It looks like the URL is already being rewritten to a filename and then you are rewriting the filename. This usually happens when the rewrite rule is being specified in an .htaccess file. The problem is due to the fact that by the time Apache reads the .htaccess file, it has already resolved all URLs to filenames. The standard solution to this is to supply a RewriteBase rule in your .htaccess. Try:
RewriteBase /
Above your RewriteRule for starters.
More documentation is here
You could try it with the additional L flag to avoid any further rules to be applied:
RewriteRule ^([^/\.]+)/$ /$1 [R,L]
But if nothing else works, try this:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ (/[^/.?\ ]+)/[? ]
RewriteRule ^[^/.]+/$ %1 [R]

301 redirect .htaccess

Im trying to request the following entire site 301 redirect:
word.something.blah.domain.com --> http://www.word.com
I don't know how to write the 301 redirect rule.
Can someone help out?
I will assume you are using the same directory to serve files on both domains. In which case, a Redirect clause won't work (infinite redirect loop).
With mod_rewrite, you can check the value of the current HTTP_HOST and take a decision based on that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.something\.blah\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.%1.com/$1 [R=301,NE,L]
put this into root directory of the subdomain:
Redirect permanent / http://www.word.com
If you are keeping everything else the same - that is, the file names - but simply changing the domain, this code is all you need to put on the OLD DOMAIN htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]