I have been struggling to get rewrite 301 rules to work. I need to maintain the existing file structure but simplify the URLs for the benefit of Google etc.
the existing file is
www.mydomain.com/abc/index.php
I want to simplify this to
wwww.mydomain.com/xyz.php
I have tried putting a rewrite rule in the root directory
RewriteRule ^xyz$ /abc/index.php [L,QSA]
and another rewrite rule in the /abc directory
Redirect 301 index.php /xyz.php
However this doesn't seem to work.
What am I doing wrong? Any help would be appreciated.
Related
Having trouble creating/finding the correct Rewrite rules for this...
domain1.com/abc -> domain2.com/crazylongurl
domain1.com/abc/def -> domain3.com/differentcrazylongurl
I currently have
RewriteEngine on
Redirect 301 /abc domain2.com/crazylongurl
And that works. But I can't get the /def subdirectory to go to a different url. Is that possible?
I figured it out! I didn't know about negative lookaheads. So, in the domain.com/abc directory, I put an .htaccess file with this in it:
RewriteEngine On
RedirectMatch 301 /abc(?!/def) domain2.com/crazylongurl
And in the domain.com/abc/def directory, I put an .htaccess file with this in it:
ReWriteEngine On
Redirect /abd/def domain3.com/differentcrazylongurl
I am trying to simplify URLs from
xyz.com/walks/walk_descrip/8010/
to
xyz.com/walk-8010
I have moved the file from the walks sub-directory to the root.
I have tried using the following in my htaccess file
Redirect 301 ^/walks/walk_descrip/(.*)/$ /walk-$1
RewriteRule ^walk-(.*)$ /walk-description.php?id=$
However this is producing URLs such as
xyz.com/walk-8010?id=8010
Where am I going wrong?
Any help would be appreciated
Redirect directive doesnt support regex. What you are looking for is RedirectMatch.
RedirectMatch 301 ^/walks/walk_descrip/(.+)$ /walk-$1
So i have this issue, with changing an old site with a new and I need to redirect all the old links. So have this:
domain.com/articles.php?var=1
I basicly want to redirect everything after articles.php to just domain.com, including the /articles.php.
Thank you in advance.
Try adding this to your htaccess file:
RedirectMatch 301 ^/articles\.php$ /
or if you have mod_rewrite rules already in your htaccess file, you need to use mod_rewrite isntead, and add this rule above whatever rules are already there:
RewriteRule ^articles\.php$ / [L,R=301]
I'm trying to 301 redirect to a child directory using .htaccess i.e.
Redirect 301 /parent http://example.com/parent/child/
Unfortunately this results in a redirect loop i.e.
/parent/child/child/child/child/etc.
Please could anyone point me in the right direction?
Redirect directive will match and redirect everything that starts with /parent. You need to use RedirectMatch to only redirect this specific folder:
RedirectMatch 301 ^/parent/?$ http://example.com/parent/child/
The same, but using mod_rewrite:
RewriteRule ^parent/?$ http://example.com/parent/child/ [R=301,L]
NOTES:
Place it in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.
Well, I have website with such structure of pages:
domain.com/group-1/page/ and now I need to make htaccess 301 redirect to
domain.com/group-1/{constant}-page/
where {constant} any fixed word (plus minus sign). This rule should not effect any other groups, except group-1
Thank You.
This can be done with mod_rewrite. Put this .htaccess code into the domain's root directory.
RewriteEngine On
RewriteRule ^group-1/page/(.*)$ group-1/constant-page/$1 [L,R=301]