This is with the reference of Fake URLs created automaticly. which was solved by https://stackoverflow.com/users/548225/anubhava.
By mistake or spam too many URLs have been created like below but now i want to redirect them to their respective post page URL.
I would prefer .htaccess. Please help
abc.com/wp-admin/post.php?post=4051&action=edit
**Redirect to**
abc.com/?p=4051
and
abc.com/page/56/?option=com_content&view=article&id=94&Itemid=2
**Redirect to**
abc.com/page/56/
and
abc.com/category5/post-about-fashion/function.include
**Redirect to**
abc.com/category5/post-about-fashion/
i am using wordpress. my permalink is /%category%/%postname%/. my htaccess code is below...
<IfModule mod_rewrite.c>
RewriteEngine On
# code by anubhava
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(page/[0-9]+/).*$ /$1? [L,NC,R=301]
# code by anubhava
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www\.deemasfashion\.com$
RewriteRule ^deemasfashion\.com/?(.*)$ http://deemasfashion.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://deemasfashion.com/ [R=301,L]
RewriteRule ^index\.htm$ http://deemasfashion.com/ [R=301,L]
</IfModule>
I believe you need 2 additional rules:
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(page/[0-9]+/?).*$ /$1? [L,NC,R=301]
RewriteRule ^(category[0-9]+/[^/]+/?).+$ /$1? [L,NC,R=301]
RewriteCond %{QUERY_STRING} (?:^|&)post=([^&]+) [NC]
RewriteRule ^wp-admin/post\.php$ /?p=%1 [L,NC,R=301]
Make sure these are top 3 rules just below RewriteEngine On
Related
I have a link like this:
From: http://www.example.com/wp/?p=231
and I need to redirect it to this URL:
To: https://www.example.com/jump/
How could this be done?
This the .htaccess file:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You need to use mod_rewrite to perform this specific redirect. And this rule should go at the very top of your .htaccess file, before all existing rules. For example:
RewriteEngine On
RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} =www.example.com
RewriteCond %{QUERY_STRING} ^p=231$
RewriteRule ^wp/$ https://%{HTTP_HOST}/jump/ [QSD,R=302,L]
UPDATE: Added the two additional conditions to check the SERVER_PORT and HTTP_HOST so that it only redirects http://www.example.com/wp/?p=231 exactly as stated. It then redirects directly to https://www.example.com/jump/.
The additional condition that checks against the QUERY_STRING server variable is necessary in order to match the query string, since the RewriteRule pattern matches against the URL-path only.
The QSD flag is necessary to remove the existing query string from the redirected response, otherwise this is passed through by default.
Depending on your .htaccess file you posted, the solution should be the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/wp/ [NC]
RewriteCond %{QUERY_STRING} p=231
RewriteRule (.*) /jump? [R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
You can check it with the following link:
https://htaccess.madewithlove.com?share=d5a7976b-47f3-4143-bb7c-103a722f0b2d
For a main domain (.nl) everything is forced over https and www.
However there is a small bug with parked domain .be
when accessed like https://domain.be/example the www. is not added.
In all other cases it is working.
.htaccess i have so far is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteRule ^(.*)$ https://www\.%1/$1 [R=301,L]
</IfModule>
Any ideas would be welcome!
Might want to check this
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have a site with Wordpress. I need some single page to redirect HTTPS
I get code form stackoverflow and put in .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /online-order-auto [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/online-order-auto [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.swtest\.ru$
RewriteRule ^(.*)$ http://www.site.ru/$1 [L,R=301]
The browser wrote "ERR_TOO_MANY_REDIRECTS".
I cant understand whats a problem
Try this. I've been looking all over and this is the only way I could make it work...
#non-www. http to www. https
RewriteCond %{ENV:HTTPS} !on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
#non-www. https to www. https
RewriteCond %{ENV:HTTPS} on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
I was hoping someone could take a look at my htaccess setup and tell me if I'm doing something wrong. Every time I try to add in one of the numerous formats I've found to redirect my page to www, I get a redirect loop.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The above works, but it goes to the base page with no www.
I've tried the following setups, and none work.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This is the code I add to the default .htaccess file that is setup with WordPress. To add the www I use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
Make sure you update WordPress Address (URL) [under general settings] as well to include www.
I am trying to redirect my whole site to non-www
here is the htaccess code I am using
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# no www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.akorra\.com$ [NC]
RewriteRule ^.*$ http://akorra.com%{REQUEST_URI} [R=301,L]
any ideas
I think your rules need to between the module tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# no www
RewriteCond %{HTTP_HOST} ^www\.akorra\.com$ [NC]
RewriteRule ^.*$ http://akorra.com%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
Here is what you need to add to your .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
However, if you are working with Wordpress as the engine that powers your entire site, just update the permalink structure and all internal settings with your domain name in it to remove the www.
EDIT:
I thought that was different when I wrote the answer Sorry. Try moving your non www rule to the top...
# no www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.akorra\.com$ [NC]
RewriteRule ^.*$ http://akorra.com%{REQUEST_URI} [R=301s,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AGAIN keep in mind if Wordpress is set to produce links with a www then nothing will stop it from reverting everything back to having a www even with a correct rewrite rule.
More Wordpress details:
Check the settings in wp/wp-admin/options-general.php ...
Be sure to remove the www in WordPress address (URL)
Be sure to remove the www in Blog address (URL)
AND then update your premalink structure in wp-admin/options-permalink.php so the changes are reflected.
After all that is said and done, be sure Wordpress did not overwrite new code in your .htaccess file.
Hi I think you need to adjust your script as follows for the rewriting to work:
Options +FollowSymlinks
RewriteEngine on
I believe that the follow symlinks absolutely has to be included for url rewriting to work properly.
More advice on mod_rewrite here:
http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html
Rob
RewriteEngine On
RewriteBase /
# no www
RewriteCond %{HTTP_HOST} ^([^.]+)\.akorra\.com$ [NC]
RewriteRule ^(.*)$ http://akorra.com/$1 [R=301,L]
# WordPres
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This should work
I suggest to use this piece of code for removing www from your website:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
it's more generic.
and in your example it's best to use this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# no www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>