I want to redirect /blog to /blog/. I have two condition if blog is in the url first condition will be called else second condition. Please anybody help me to do this.
I did this.
#blog
RewriteCond %{REQUEST_URI} ^/blog.*
RewriteRule (.*) /blog/$1 [L]
#squeezepage
RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)$ index.php?option=com_squeezepage&sqpage=$1 [NC]
Thanks.
You can do something like this to redirect /blog to /blog/ however if /blog is a physical folder then Apache does it automatically for you:
RewriteRule ^blog$ /blog/ [L,R=301,NC]
Do you only want the trailing slash for /blog requests or do you want it for all directories?
Because there is a directive called DirectorySlash on which might be what you're looking for.
See this question.
Related
I want to redirect
www.example.com/mydomain?data1=value1&data2=value2
to
mydomain.example.com/?data1=value1&data2=value2
I want to redirect with the PHP variables passed to it.
How do I do that with the .htaccess file? I am sorry if this is answered elsewhere, I can't find it with search.
This is a straightforward rewrite, but...
...you need to know about the mod_rewrite Query String Append Flag ([QSA]):
The mod_rewrite rule to add to the root folder of www.example.com is:
RewriteEngine On
RewriteRule (.*) http://$1.example.com [R=301,QSA]
In your public_html/.htaccess, you can use :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^mydomain/?$ http://mydomain.example.com/ [NC,QSA,L,R]
This will redirect
http://example.com/mydomain?query_strings
to
http://mydomain.example.com/?query_strings
I have domain-a.com and domain-b.com. The host runs a multi-site Contao installation with two sites to which both domains are assigned respectively. Both sites are supposed to have a Wordpress blog in a /blog subfolder. Of course they realistically can not, so the first one is domain-a.com/blog and the second is domain-b.com/blog-b.
Wrapping my head around .htaccess has proven to be really difficult for me and I just can't figure out how to get this logic to work:
if
domain is domain-b
and
request_uri starts with /blog
rewrite to domain-b/blog-b/$1
I tried like this:
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.comt [NC]
RewriteCond %{REQUEST_URI} ^/blog/
RewriteRule ^/(.*) /blog-b/$1
Does not work. How is it done?
Ah, I think the $1 is capturing the /blog/ in the incoming url, so it's doing /blog-b/blog/...
Try this:
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.com [NC]
RewriteRule ^/blog/(.*)$ /blog-b/$1 [NC,L]
Also, depending if you have a RewriteBase, the leading slash in the RewriteRule may need to be removed.
I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.
Lets say I have a two websites www.sample.com and files.sample.com.
In an .htaccess file within the webroot of www.sample.com, I have the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{QUERY_STRING} ^files\/uploads [NC]
RewriteRule ^(.*)$ http://files.website.com/$1 [NC,L]
</IfModule>
The desired result is to have all requests of www.sample.com/files/uploads/file.xml or www.sample.com/files/uploads/subfolder/file.json get 302 redirected to files.sample.com/files/uploads/file.xml and www.sample.com/files/uploads/subfolder/file.json, respectively.
However, I can't get the rule to fire. The directory "files" does not exist on the www.sample.com website at all.
Could anyone give me a little help as to why the
You probably want REQUEST_URI not QUERY_STRING.
RewriteCond %{REQUEST_URI} ^/files\/uploads [NC]
Also note the leading slash.
Did you turn on mod_rewrite in your apache config?
Also yor change '^files/uploads' to ^/files/uploads and QUERY_STRING to PATH_INFO.
QUERY_STRING - this is all data after '?' character.
I have a index.php in my main domain root
domain.com/index.php
And ive moved my forums which was in the same "root" to a subdomain
forums.domain.com
I need to Redirect everything except the index.php
ive tryed loads of ways and none seem to work
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !index\.php$
RewriteRule ^(.*)$ http://forums.domain.com [L,R]
RewriteEngine On
RewriteCond %{HTTP_HOST} animelon\.com [NC]
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteRule ^(.*)$ http://forums.domain.com/$1 [R=301,L]
If anyone has any ideas that would be great
as for the above codes I would them googling about.
Cheers
You may use RedirectMatch instead of rewriting, that is, replace all the rewrite block you are showing with:
RedirectMatch ^(/(?!index\.php).*) http://forums.domain.com$1
You can see the full explanation of the regex on Regexr here. In brief, it sends all the URIs NOT beginning with /index.php to forums.domain.com.
If you don't need any other rewrite rule, you can turn off rewriting by removing all the lines beginning with "Rewrite" from your .htaccess.