Im trying to redirect this,
example.com/slide?page=4 to example.com/slide/issue43?page=4
But it cannot effect other URL's like, example.com/slide/issue57?page=4
Im really stuck, these regular expressions are so weird. Here's the rewriterule that I've come up with,
This is not working
RewriteRule ^slide?page(.*)$ http://example.com/slide/issue43?page=$1 [L,R=301]
I need to target 'slide?page=X' specifically and have it redirect or point to 'slide/issue43?page=X'
This should work for you:
RewriteCond %{REQUEST_URI} ^/slide$
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^(.*) /slide/issue57?page=%1 [R=301,L]
Related
im quite new to rewrite rules.
I can manage with one variable and thats it.
I have webpage Where the rewriterule is:
RewriteCond %{HTTP_HOST} ^www\.someserver\.com$
RewriteRule ^/?$ "http\:\/\/someserver\.com\/" [R=301,L]
RewriteRule ^(\d+)*$ ./index.php?comp=$1
RewriteRule ^(\d+)*/$ ./index.php?comp=$1
And it all work fine as it should. But now as i want 1 more variable into URL
i cant get it to work.
Right now the $1 is only numbers.
someserver.com/1554886
But i want two variable.
someserver.com/1554886-SOMENAME-WHATEVER-WORD-AND-HOW-MANY
But it wont show.
i tried smth like this:
RewriteRule ^([^-]*)-([^-]*)$ ./index.php?comp=$1&string=$2 [L]
How do i get it to work?
Do i have to make some changes in the php side as well?
everything what comes after the number part of the URL is there only for
SEO, the number is Unique
You need one more rule to handle two parameters:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(someserver\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(\d+)/?$ index.php?comp=$1 [L,QSA]
RewriteRule ^(\d+)-(.+)/?$ index.php?comp=$1&string=$2 [L,QSA]
I moved from a wordpress to a typo3 site. On my old sites, the links looked like this:
http://www.example.org/?page_id=44
now I want to redirect it to:
http://www.example.org/contact
Usually the redirects-rules are no problem, but this time I don't get it why it is not working:
I tried this:
Redirect 301 /?page_id=44 http://www.example.org/contact
as well as this:
RewriteRule http://www.example.org/\?page_id=44 http://www.example.org/contact [R=301,L]
and this here:
RewriteCond %{REQUEST_URI} ^example.org/\?page_id=44
RewriteRule ^(.*)$ http://www.example.org/contact [R=301,L]
Tried it in several browsers and incognito-mode, but it still remains wrong, it still adds the parameter instead of redirecting to the certain page.
I guess it is somehow doable with %{query_STRING} ?
Is it due to the param-thingy?
Any ideas how to solve this problem?
Okay, got it. It had something to do with the query string:
Final result:
RewriteCond %{QUERY_STRING} ^page_id=14$ [NC]
RewriteRule ^(index\.php){0,1}$ /kontakt/? [L,R=301,NC]
You can use:
RewriteCond %{THE_REQUEST} /\?page_id=44\s [NC]
RewriteRule ^/?$ /contact? [R=301,L]
I am having trouble getting
site.com/member-videos
into
site.com/videos
or in reality
#RewriteCond %{HTTP_HOST} !^/community/member-videos/
#RewriteRule (.*) http://site.com/community/videos/$1 [R=301,L]
this seems to loop !
for me the above says find the match for '/community/member-videos/' and send anything like that to the url after...I have lost too much time now on this typical I would guess issue and looked at a lot of similar online but nothing quite works for this case..
thanks
RewriteRule (.*) http://site.com/community/videos/$1 [R=301,L]
This is wrong, it will get you into an infinite loop.
Try this one:
RewriteRule http://site.com/community/member-videos/$1 ^community/videos/(.*)$ [R=301,L]
You almost had it. The variable your condition matches against is a host, and not a URI. If you need to check the host, it must only be the hostname (not URI path at all), e.g. site.com. You need to use a %{REQUEST_URI} variable for what you are matching against:
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/videos/
RewriteRule ^/?member-videos(.*)$ /videos$1 [L,R=301]
The example you gave doesn't have the community part in the URI at all, if it's not in the URL, it won't appear in the string sent to the rewrite engine. But your rules has /community in them, so if in fact you need that path, then:
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/community/videos/
RewriteRule ^/?community/member-videos(.*)$ /community/videos$1 [L,R=301]
I need this logic to work:
I want rewrite this string for users to see
http://mysite.com/index.php?cl=mykeystring
to
http://mysite.com/otherkey/
http://mysite.com/index.php?myvar=test&cl=mykeystring&mysecondvar=morevalue
to
http://mysite.com/otherkey/myvar=test&mysecondvar=morevalue
But when http://mysite.com/otherkey/ is written, so load
http://mysite.com/index.php?cl=mykeystring, but no redirects will be done.
Is it possible? There are no possibility to change anything in codes, but only .htaccess
This logic is nearly realized by this code:
RewriteCond %{QUERY_STRING} ^(.*?)cl=mykeystring(.*?)$ [NC]
RewriteRule ^index.php$ /otherkey/%1%2? [R,L]
RewriteRule ^otherkey/(.*?)$ /index.php?cl=mykeystring&$1
but im getting some not needed amp symbols on first rewrite rule. any solutions?
I think you can do something like this:
RewriteCond %{QUERY_STRING} cl=mykeystring [NC]
RewriteRule ^index.php /otherkey/ [QSA]
Docs here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
I found myself with this problem, which is driving me a little bit crazy. I use apache's mod_rewrite for pretty URLs and I need to use dynamic subdomains in the site. Everything is great and all the server has de wildcards. I use the next code on my .htacess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.com
RewriteCond %{HTTP_HOST} ([^.]+).mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/%1 [L]
The only problem is, even if I use the [L] flag the url of the site change to http://mysite.com/subdomain. What i want is the url to be like http://subdomain.mysite.com
The link mysite.com/subdomain is a dynamic url and is solved with another rule with the following code:
RewriteRule ^([A-Za-z]+)$ filter.php?type=subdomain&subdomain=$1
Any help would be appreciated
If you specify an external URL (which changing the subdomain does), a header redirect will take place. I don't think you can prevent that. But why not skip that step altogether, and use the second RewriteRule straight away?
I can't test this right now, but something like
RewriteCond %{HTTP_HOST} !^www.mysite.com
RewriteCond %{HTTP_HOST} ([^.]+).mysite.com [NC]
RewriteRule ^(.*)$ filter.php?type=subdomain&subdomain=$1
should work.