I'm trying to redirect all urls that contain a specific string. The urls look like this
http://www.domain/com/modules.php?name=Kalender&op=list&d=8&m=6&y=2034
I have to redirect all urls that contain
name=Kalender&
to
http://www.domain.com/kalender/
I tried several rules in my .htaccess. None of them worked:
RewriteCond %{REQUEST_URI} name=Kalender&
RewriteRule .* kalender
RewriteRule ^(.)name=Kalender&(.)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/name=Kalender&/i$ http://www.domain.com/kalender/ [NE,L]
RewriteCond %{REQUEST_URI} name=Kalender&
RewriteRule ^(.+)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{QUERY_STRING} ^name=Kalender&
RewriteRule ^name=Kalender& http://www.domain.com/kalender/ [R=301,L]
RewriteRule ^(.*)name=Kalender&(.*)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/modules.php?name=Kalender&$
RewriteRule ^(.*) http://www.domain.com/kalender [R=301,L]
This is the WordPress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any help would be appreciated!
You can use this rule as your first rule:
RewriteCond %{QUERY_STRING} (^|&)name=Kalender(&|$) [NC]
RewriteRule ^ /kalender/? [L,R]
Related
I need to remove get params from url-string.There is code from .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://formaspravki.com? [R=301,L]
RewriteCond %{HTTP_HOST} ^www.formaspravki\.com
RewriteRule ^(.*)$ http://formaspravki.com/$1? [R=permanent,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.forma-spravki\.com
RewriteRule ^(.*)$ http://formaspravki.com/$1? [R=permanent,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forma-spravki\.com
RewriteRule ^(.*)$ http://formaspravki.com/$1? [R=permanent,L]
DefaultLanguage ru
AddDefaultCharset windows-1251
#php_value default_charset "cp1251"
# Редиректы
RewriteRule ^page/([0-9]+)(/?)$ index.php?cstart=$1? [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/page/([0-9]+)(/?)+$index.php?do=cat&category=$1&cstart=$2[L]
RewriteRule ^([^.]+)/?$ index.php?do=cat&category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/rss.xml$ engine/rss.php?do=cat&category=$1 [L]
RewriteRule ^page,([0-9]+),([^\/]+).html$ index.php?do=static&page=$2&news_page=$1 [L]
RewriteRule ^print:([^\/]+).html$ engine/print.php?do=static&page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\/]+).html$ index.php?do=static&page=$1 [L]
Redirect 301 /spravka_rabotodatelyu_o_beremennosti.html http://formaspravki.com/spravka-o-beremennosti.html
Redirect 301 /spravka_o_beremennosti_obrazec.html http://formaspravki.com/spravka-o-beremennosti.html
Afer redirecting, in url string appears parametrs ?do=static&page='page name'.
When I add next code paramets disappering,but content in browser isn`t loading:
RewriteCond %{QUERY_STRING} !="^do=static$"
RewriteRule ^(.*)$ http://example.com/$1? [L]
Adding '?' to the directive or deleting query string didnt help.
Try appending [QSD] flag to your url, for example:
RewriteRule ^index\.php$ http://example.com [R=301,L,QSD]
Problem is solved!
RewriteCond %{QUERY_STRING} "^do=static&page=old-name$"
RewriteRule ^([^\/]+)$ new-link$1? [R=permanent,L]
I have url with query in the midle of request uri ex:
http://domain.com/index.php?/recipe_category/recipe/
I've trying to remove the index.php as well but it leave the query sign (?) so the url become
http://domain.com/?/recipe_category/recipe/
How to remove all of the [index.php?]? For your information, my htaccess written as below :
RewriteEngine On
RewriteCond %{SERVER_NAME} !^www.domain.com$
RewriteRule .* http://www.domain.com%{REQUEST_URI} [R=301,L]
RewriteRule ^index.php/(.*)$ http://www.domain.com/$1 [R=302,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
You can use following lines to remove "index.php?"
RewriteEngine On
RewriteRule ^index.php\?(.*)$ http://www.domain.com/$1 [R=302,L]
I have the following code that redirects any http:// request to https:// - This work great, but how would I edit this to make an exception for one page e.g. mydomain.com/sitemap-news.xml - and keep this as http:// ?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
As listed in comments here is how my entrie .htaccess looks
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule !^sitemap-news\.xml$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} off
RewriteRule !^sitemap-news\.xml$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NE]
You can make an exception for sitemap file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule !^sitemap-news\.xml$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} off
RewriteRule !^sitemap-news\.xml$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
i have this url
http://myurl.com/shiftturn/index.php?m=value
and i want:
http://myurl.com/shiftturn/value
this is my .htaccess
RewriteEngine On
RewriteRule /shiftturn/([^/]*)$ /index.php?m=$1 [L]
but doesn't work.
how can I do to get the kind of url I need, with a correct htaccess expression?
Place this rule in /shiftturn/.htaccess:
RewriteEngine On
RewriteBase /shiftturn/
RewriteCond %{THE_REQUEST} /index\.php\?m=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?m=$1 [L,QSA]
I tried doing some .htaccess redirects for internal pages but they are not working for me. This is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule articles articles/how-to-play-piano [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I also tried this outside <IfModule> but not working:
Redirect 301 http://www.domain.com/articles http://www.domain.com/articles/how-to-play-piano
and
Redirect 301 /articles http://www.domain.com/articles/how-to-play-piano
Your regex is wrong for articles rule and will cause infinite looping. To fix that you need to use anchors ^ and $:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule ^articles/?$ articles/how-to-play-piano [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]