I want to use 301 redirects for my website URLs. The URL redirects to the wrong path and the website give me a 404 error. When I use this redirect.
Redirect 301 /couponstore/evitamins-120 https://website.com/codes/evitamins-coupon-codes
it gives me a result like this
https://website.com/codes/evitamins-coupon-codes?lcp=couponstore/evitamins-120
the lcp=couponstore/evitamins-120 is an extra part and it is injected to the URL due to the .htaccess rewrite. When I remove the last part of the rewrite rule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L] then my website stop working and I am getting errors on all pages.
Below is the .htaccess code for my website:
<IfModule mod_rewrite.c>
## Turn on rewrite engine
RewriteEngine on
## Coupons CMS v7
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L]
</IfModule>
what should I do to use redirects for my website URLs, I lost all the SEO for my website due to this one issue which I am not capable to resolve, need suggestion/help to redirect old URLs to the new.
thank you.
Based on your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
## Turn on rewrite engine
RewriteEngine ON
## Coupons CMS v7
RewriteRule ^(couponstore/evitamins-120)/?$ codes/evitamins-coupon-codes [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L]
</IfModule>
Related
I had old html website which had .html pages and i want to redirect to non .html pages which wordpress has.
for eg.
Old site
http://myweb212.com/About-Us/jony-test.html
wordpress site.
http://myweb212.com/About-Us/jony-test
There are many pages in website so is this possible do this with one rule?
I tried using a rule but it breaks some of the images of upload folder and shows 404.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
RewriteRule . /index.php [L]
</IfModule>
Inserting the new rule between another rule (RewriteRule) and its associated conditions (RewriteCond) breaks this other rule.
So when you move the rule to the beginning or to the end, it should work as is.
One minor nitpick, never test with R=301! When everything works as it should, you may replace R with R=301 (permanent redirect).
I have an existing site with php in the URL indexed. I want to change the URLs to not include PHP so thepage.php will be rewritten to http://example.com/thepage
The rewrite is working, but the redirect causes a 'page can't be displayed in a loop' error when I try to access the page as using thepage.php
I need to figure out how to setup the redirect and also rewrite the URLs, because Google has now indexed the PHP URLs and the pretty URLs.
I've looked at countless pages online, but can't find the answer.
Please help.
Here's my htaccess
# The redirect below caused a loop when I access the page as
# http://example.com/thepage.php
# Moving the redirect after the rewrite didn't work either.
Redirect 301 /thepage.php http://example.com/thepage
RewriteEngine on
# Rewrite works. The page does display corectly for this link
# http://example.com/thepage
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
# RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteRule ^photos([^\.]+)$ photos [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
ErrorDocument 404 http://example.com/
Thank You
Your rewrite rule is backward from the sounds of it.
Here we're capturing all php files that do no contain periods and redirecting them to a directory URI using only the name without the extension. [R=301] is a permanent 301 redirect that tells whoever that the page is no longer in its old place.
RewriteEngine on
RewriteRule ^([^\.]+).php$ $1 [NC,L,R=301]
You might want to test these with R only without the 301 to make sure it's working. If you do a 301 redirect that doesn't work it will be cached in the end user's browser cache until it expires.
Apache has an extensive reference on remapping URLs with redirects.
I finally was able to get back to this problem and found the solution. I hope this can help somebody else. I tore my hair out on this problem.
I found many examples but not with the combination that I needed
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
RewriteBase /
# hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]
# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
ErrorDocument 404 http://example.com/
I am working on a php redirect script which 302 redirects visitors to other sites when they access a redirect url..
The script gets a variable (id) from the url and then redirects the visitor to the specific page.
The url structure is : example.com/redirect/index.php?id=test
At the moment all redirects work if I use "ugly" urls, but I want to strip all unnessecary information out of the url with .htaccess rewrites for better usability.
Which .htaccess rewrite rules do I need to make the above shown urls look like : example.com/redirect/test
I am currently using the following .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
but they only work for urls like example.com/redirect/index.php?id=test if I try example.com/redirect/test I get a 404 error page.
It might be good to know, that I have 2 .htaccess files, one in my root directory and one in the root/redirects/ directory.
Best regards !
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)?/?([^/]+)?/?([^/]+)?/? [NC]
I used a generator to make my SEO friendly htaccess rewrite, here it is.
RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]
The output should be www.site.com/type/id
Now, the rewrite works and pages redirect fine, BUT the images on the site no longer show up, they're all broken... :( The URL for the images is right but seems it just doesn't want to load anymore, any help? Should there be another Rewrite rule to cancel out this one from doing other stuff? If so, what?
Your existing rule could affect images. To prevent that, use a RewriteCond directive that will exlcude extensions for images etc. being affected by the rule You can add other extensions as necessary.
#if its not an image, css, js etc
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc)$ [NC]
RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]
I'm not sure how your .htaccess looks like, but here is handy rules that I'm using for my projects, it's pretty simple and covers most of the problems:
<IfModule mod_rewrite.c>
############################################
# Enable mod_rewrite
RewriteEngine On
RewriteBase /
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|assets)/
############################################
# never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .*$ index.php [L]
</IfModule>
I am updating an old asp site to cakephp - the old site has various listings on google based on the old "filename.asp" urls - I'd like to put Redirect 301s in the htaccess file to try and hang on to those search results (most of the pages have a complementing page on the new site), but something appears to be going wrong. htaccess as follows (excluding standard cake stuff). What am I doing wrong?
Redirect 301 contact.asp /contact
Redirect 301 portfolio.asp /portfolio-design-web
Redirect 301 webhosting.asp /
I've tried with the htaccess in the root directory, and webroot but it should just work wherever, no?
--
fixed it using mod_rewrite, following rules inside .htaccess on webroot work:
RewriteRule ^contact.asp$ /contactos/ [R=301,L]
Try modifying app/webroot/.htaccess like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^contact.asp$ /contact [R=301,L]
RewriteRule ^portfolio.asp$ /portfolio-design-web [R=301,L]
RewriteRule ^webhosting.asp$ / [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>