I am having a issue with my urls google have crawled double http for example
http://example.com/example.com/c-title-id.html
and all the interlinked pages like that
please can any one help me out to redirect all the urls with 301 with .htacess
My htacess code is
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.website\.com [NC]
RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]
RewriteRule category-([0-9]+)-(.*)-([0-9]+)\.html$ category.php?cid=$1&name=$2&page=$3.php [L]
RewriteRule search-(.*)-([0-9]+)\.html$ search.php?term=$1&page=$2.php [L]
RewriteRule all-covers-([0-9]+)\.html$ all-covers.php?page=$1.php [L]
RewriteRule index-([0-9]+)\.html$ index.php?page=$1.php [L]
RewriteRule featured-covers-([0-9]+)\.html$ featured-covers.php?page=$1.php [L]
RewriteRule top-downloaded-([0-9]+)\.html$ top-downloaded.php?page=$1.php [L]
RewriteRule c-([0-9]+)(.*)\.html$ cover.php?id=$1&name=$2.php [L]
RewriteRule sitemap.xml$ sitemap.php [L]
RewriteRule sitemap1.xml$ sitemap1.php [L]
RewriteRule rss.xml$ rss.php [L]
RewriteRule ^(.*)\.html$ $1.php [L]
ErrorDocument 404 /404.html
I want to redirect all of them automaticaly.
Should be as simple as having this at the top of your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.website\.com [NC]
RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]
RewriteRule example\.com/(.*)$ /$1 [R=301,L]
#... rest of your rules...
Related
I am having some trouble with my htaccess code:
RewriteEngine on
RewriteRule ^about\/$ /about.php [L]
RewriteRule ^about?$ /about/ [L,R]
RewriteRule ^contact\/$ /contact.php [L]
RewriteRule ^contact?$ /contact/ [L,R]
RewriteRule ^([A-Za-z0-9\-]+)\/gallery\/$ /loc-gallery.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/gallery?$ /$1/gallery/ [L,R]
RewriteRule ^([A-Za-z0-9\-]+)\/location\/$ /loc-location.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/location?$ /$1/location/ [L,R]
RewriteRule ^([A-Za-z0-9\-]+)\/contact\/$ /loc-contact.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/contact?$ /$1/contact/ [L,R]
RewriteRule ^([A-Za-z0-9\-]+)\/$ /loc-home.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)?$ /$1/ [L,R]
The problem is that if i want to access:
http://example.com/about
http://example.com/contact
i am not redirected to
`http://example.com/about/` and `http://example.com/contact/`
and when i try to access http://example.com/ i am redirected to http://example.com//
What i am doing wrong? Thanks in advance!
When you try to access http://example.com/ i am redirected to http://example.com// is happening because of this line :
RewriteRule ^([A-Za-z0-9\-]+)?$ /$1/ [L,R]
It will match the empty URI because of this regex ^([A-Za-z0-9\-]+)?$
it means match if ([A-Za-z0-9\-]+) then or not ? .
It should look like this :
RewriteRule ^([A-Za-z0-9\-]+)$ /$1/ [L,R]
I also sumerized your code and fixed some issues like this :
RewriteEngine on
RewriteRule ^about(\/)?$ /about.php [L]
RewriteRule ^contact(\/)?$ /contact.php [L]
RewriteRule ^([A-Za-z0-9\-]+)\/gallery(\/)?$ /loc-gallery.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/location(\/)?$ /loc-location.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/contact(\/)?$ /loc-contact.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)\/$ /loc-home.php?slug=$1 [L]
RewriteRule ^([A-Za-z0-9\-]+)$ /$1/ [L,R]
Clear browser cache and test it , if it is ok change R to R=301 to get permanent redirection
I want Redirecting Subfolder to Subdomain with htaccess
I have this code
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sitename.com[NC]
RewriteRule ^(.*)$ http://www.sitename.com$1 [L,R=301]
RedirectMatch 301 ^/subfolder/(.*)$ http://subdomain.sitename.com/$1
but when redirect categories get link like this
http://subdomain.sitename.com/5/cat?c=5
it should become like this
http://subdomain.sitename.com/5/cat
this is the full htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^game-([0-9]+).html$ file.php?f=$1 [L]
RewriteRule ^([0-9]+)/(.+?)/([a-zA-Z]+)?/?([0-9]+)\.html$ browse.php?c=$1&p=$4 [L]
RewriteRule ^([0-9]+)/(.+?)?$ browse.php?c=$1 [L]
RewriteRule ^profile/([0-9]+)/.+\.html$ profile.php?u=$1 [L]
RewriteRule ^page/(.+)\.html$ page.php?p=$1 [L]
RewriteRule ^scores/([0-9]+)/([0-9]+)\.html$ scores.php?f=$1&p=$2 [L]
RewriteRule ^game-[0-9]$ $1.php [L]
RewriteRule ^game-[0-9]$ arcade/gamedata/$1 [L]
RewriteRule ^g([0-9]+)/?$ links.php?a=short&f=$1 [L]
RewriteRule ^tag/(.+?)(|/|/([0-9]+)\.html)$ search.php?t=$1&p=$3 [L]
</IfModule>
thanks
I wrote rules to rewrite url
RewriteRule ^([a-zA-Z0-9-/]+)$ news.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ news.php?id=$1
but I need that http://mysite.com/blog/ not to be rewritten by these rules.
Thanks for you advices :).
My .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !news\.php [NC]
RewriteCond %{REQUEST_URI} !/blog [NC]
RewriteCond %{REQUEST_URI} ^/([^/]+) [NC]
RewriteRule .* news.php?id=%1 [R=301,L]
RewriteRule ^video_([^/]+) video.php?page=Video&table=$1
RewriteRule ^en/([a-zA-Z0-9-/]+)$ en/news_en.php?no=$1
RewriteRule ^en/([a-zA-Z0-9-/]+)/$ en/news_en.php?no=$1
RewriteRule ^it/([a-zA-Z0-9-/]+)$ it/news.php?id=$1
RewriteRule ^it/([a-zA-Z0-9-/]+)/$ it/news.php?id=$1
RewriteRule ^photo_([^/]+) photogalery.php?page=Photo&part=$1
RewriteRule ^en/photo_([^/]+) en/photogalery.php?page=Photo&part=$1
RewriteRule ^it/photo_([^/]+) it/photogalery.php?page=Photo&part=$1
ErrorDocument 404 /404.html
use
RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9_-]+)$ news.php?id=$1
I have the following .htaccess config
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule \.git - [F,L]
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
RewriteRule ^users/([0-9]+) profile.php?id=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)?$ profile.php?u=$1 [L]
Now, whenever somebody visits the landing page, they get redirected using the last rule for profile.php?u=$1.
How do I change the configuration so that www.example.com and www.example.com/ are mapped to index.php and not profile.php?
Match the empty string or single slash just after the ^index rule:
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
# Match root request with optional slash
RewriteRule ^/?$ index.php [L]
I will suggest not to do it this way.
Instead, simply user this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This will send all your requests to index.php page, from there create a router.php and pass on the requests to that page, using php.
but in case you do, just add
RewriteRule ^/?$ index.php [L]
Like Michael suggested.
Here is a simple tool to test your rules, if you wish to
Apache RewriteRule tester
I have this .htaccess:
RewriteEngine On
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L]
RewriteRule ^(.*)$ path/to/another/file/$1 [L]
I want urls in the form of www.website.com/!/this/ to be rewritten to path/to/a/file. Any URL that doesn't match that pattern should be rewritten to path/to/another/file/.
Here's what I've tried to far:
RewriteEngine On
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L]
RewriteCond ...
RewriteRule ^(.*)$ path/to/another/file/$1 [L]
When using the above rewrite rule, I get a 500 - Internal Error.
How can I fix it?
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/!
RewriteRule ^!/([a-z0-9_\-\.]+) user/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/!
RewriteRule ^([a-z0-9_\-\.]+)/([a-z0-9_\-\.]+)/?$ $1/controller/front.php/$2 [L]
RewriteCond %{REQUEST_URI} !^/!
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ $1/controller/front.php/$2/$3 [L]