I need some quick help cleaning up the following rules for htaccess file, as the list is getting quite long.
This has occurred after a site move which makes author pages that previously came from /browse/author/NAME-HERE now sit at /by/NAME-HERE.
Surely there's a way to pattern match these or something?
Redirect /browse/author/some-person /by/some-person
Redirect /browse/author/another-person /by/another-person
Redirect /browse/author/some-other-person /by/some-other-person
Redirect /browse/author/yet-more /by/yet-more
Redirect /browse/author/ /
I'd like to keep the /browse/author/ redirect to the root though, if possible...
Many thanks for any help!
This is definitely possible with mod_rewrite.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/?browse/author/(.*) /by/$1 [L,R=301,NC]
Related
I have found many 301 htaccess redirects examples but i need something specific and dont know how to build that exact redirect rule... the site i am build this for is a wordpress site.
Example:
http://www.example.com/article/some-article-01.html
http://www.example.com/article/data-analysis.html
http://www.example.com/article/another-page.html
To redirect to:
http://www.example.com/article/some-article-01/
http://www.example.com/article/data-analysis/
http://www.example.com/article/another-page/
looking for one htaccess rule that works in wordpress...
a pointer to relevant data would be accepted hapily. cant seem to find the right search query. An example code would be of course much more easier.
Insert this rule in your DOCUMENT_ROOT/.htaccess file as very first rule just below RewriteBase line:
RewriteEngine On
RewriteBase /
RewriteRule ^(article/[^.]+)\.html$ /$1/ [L,NC,R=302]
If it works for you then change 302 to 301 to make it permanent redirect.
I want to rewrite following url,
http://example.com/widgets/search.js?id=qerwtwttw45777
as follows,
http://example.com/widgets/search/qerwtwttw45777
and tried following rule in htaccess,
RewriteEngine on
RewriteBase /
RewriteRule search/(.*)/$ /widgets/search.js?id=$1
but it fails and showing
**500 Internal Server Error**
Anybody help to solve this problem.
Thanks
Place this code in /widgets/.htaccess:
RewriteEngine on
RewriteBase /widgets/
RewriteRule ^search/([^/]+)/?$ search.js?id=$1 [NC,L,QSA]
Make sure mod_rewrite is enabled.
Apart from the surplus slash / at the end of the pattern, the rule looks fine. So, it must be some other problem.
Maybe, mod_rewrite isn't active for your website. You could either look into the server's error log, if available or try just
RewriteEngine on
without anything else.
If it still has the 500 Internal server error, rewrite is most likely not available.
I'm trying to perform the following 301 redirects.
/blog/ is not redirected.
/blog/xxxxx/ is redirected to /blog/
/blog/page/x is not redirected
I'm no expert with regex and after digging through quite a few stackoverflow posts I came up with this:
RedirectMatch 301 /blog/((?!page/.*)[0-9a-zA-Z\-]{1,})*/ http://www.xxxxxxx.com/blog/
While this works on my mac, for some reason it isn't working in chrome on my PC (reports an infinite loop when on the /blog/ page, same with IE).
I originally had written this in a more simple manner, without the [0-9a-zA-Z\-]{1,} section. Including this was my attempt to fix the infinite loop problem on chrome#windows.
EDIT: I also tested it with an online regex tool and it seems to work fine:
http://imgur.com/pSRCn5b
Can anyone provide any pointers?
Clear your browser's cache first and use R=302 in your testing.
Better use mod_rewrite for this.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(blog)/([^/]+)/?$ /$1 [L,R=302,NC]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I need help writing an htaccess redirect or rewrite rule (mod_rewrite.c) to handle the following situation:
http://www.mysite.com/archive/[YEAR]/archive/[YEAR]/[CORRECT-PATH]
should redirect to:
http://www.mysite.com/archive/[YEAR]/[PATH]
Basically, there are some externals links that have incorrectly doubled-up on the /archive/[YEAR]/ part of the path, where there should only be one instance. I have a sub-directory for each year (/archive/2011, /archive/2012, etc.) - those year directories are the roots of separate Drupal installations - each with their own .htaccess file (which is tripping me up).
The [CORRECT-PATH] bit is usually an alias to a Drupal page, for example:
http://www.mysite.com/archive/2012/winners/all
I'm not so good with wildcard and matching syntaxes - any help would be appreciated. Thanks.
Try adding these rules to your document root:
RewriteEngine On
RewriteRule ^/?archive/([0-9]{4})/archive/\1/(.*)$ /archive/$1/$2 [L,R=301]
This checks that the year is duplicated, for any 4 digit year. so:
http://www.mysite.com/archive/1234/archive/2345/blah/blah does nothing
http://www.mysite.com/archive/2345/archive/2345/blah/blah gets redirected to
http://www.mysite.com/archive/2345/blah/blah
http://www.mysite.com/archive/1234/blah/blah does nothing.
After looking at your problem again, you're going to need to add rules to each of your /archive/[YEAR] directories:
RewriteEngine On
RewriteBase /archive/2011/
RewriteRule ^archive/[0-9]{4}/(.*)$ $1 [L,R=301]
And change the RewriteBase for each of your directories.
I've got a problem with Codeigniter where it's processing
domain.com/domain.com/URI
Without generating a 404 error. Basically it's just loading domain.com/URI without chaning the url. So, I've got a potential duplicate content problem on my hands.
Rather than trying to hack the core, I'd like to change the htaccess to redirect
domain.com/http://domain.com/URI
to simply
domain.com/URI
I've tried googling solutions but none of them seem to be triggering the rewrite condition. Any ideas?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://[^/]+(/[^\s]*) [NC]
RewriteRule ^ %1 [R,L]