Hi I need to redirect using htaccess every request which points at:
http://www.mydomain.com/index.php?option=com_content&view=category&layout=blog&id=293&Itemid=387
to this url:
http://www.otherdomain.com
I've try to do it by:
redirect /index.php?option=com_content&view=category&layout=blog&id=293&Itemid=387 http://www.otherdomain.com
But it doesnt work. So I need Your help.
Better to use mod_rewrite for this stuff.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&layout=blog&id=293&Itemid=387$
RewriteRule ^index\.php$ /? [L,R=302,NC]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I think someone may need to extend my answer but you'll be looking to do something along the lines of:-
RewriteRule ^([^/]+)/? index.php?option=$1 [R=301,L]
The rule will require a regular expression so the server can compare the request.
Related
I want to rewrite a specific file on my website to another one by using htaccess:
# General
RewriteEngine On
RewriteBase /
Options All -Indexes
Options +FollowSymLinks
# Rewrite file
RewriteRule ^/file.html$ /dir/file.html [L]
This is the .htaccess code i'm using based on snippets i found on the internet.
Somehow this is not working, the server is returning a 404-Not-found error.
I can't see any difference with example's that are said to work, like in
Rewriting path for a specific file using htaccess
Edit:
If I place file.html in the root-folder, I can view it. So the rewrite definitely is not happening.
RewriteRule does not receive leading slash. Write so:
RewriteRule ^file.html$ /dir/file.html [L]
I need to redirect all Url which contain "forums" in address bar!!
Like:http://www.sportsinjuryclinic.net/blog/forums/ to http://www.sportsinjuryclinic.net Can any one help me to do that redirection?
Thanks
You will need to use Mod_rewrite and a regex to check for the "forums" string. Here is an example of what you're looking for.
mod_rewrite rule: if URL contains a certain string
Rule 1:
If /blog/ is a directory then place this rule in /blog/.htaccess:
RewriteEngine On
RewriteBase /blog/
RewriteRule ^forums(/.*)?$ / [L,NC,R=302]
Rule 2:
For handling /forums/ place this rule inDocuementRoot/.htaccess`:
RewriteEngine On
RewriteRule ^forums(/.*)?$ / [L,NC,R=302]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I've been pulling my hair out trying to get a URL rewrite rule to work using .htaccess. Mod_rewrite is enabled and I have managed to get a 301 redirect to work (from /beta to /Beta/) so I know the .htaccess is able to work.
Basically I'm trying to get /Beta/Page.php?id=page&tab=services&tabid=tab1 to become /page/services (and ideally leave out the tabid if it's not going to break the site removing it).
The code I'm working with currently is:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3
redirect 301 /beta http://www.example.com/Beta/
Any help would be gratefully received.
Remove the leading slash:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(Beta)/[^.]+\.php\?id=([^&]+)&tab=([^\s&]*)&tabid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=302,L]
RewriteRule ^Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3 [L,QSA]
This will externally redirect:
/Beta/Page.php?id=page&tab=services&tabid=tab1
to
/Beta/page/services/tab1
and rewrite same URI internally.
Also .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
I don't think this is possible, however I would like to ask the community to see if it is.
I have a blog on a subdomain blog.domain.com due to a revamp of the site we are having to use the blog on a trailing domain domain.com/blog this isnt ideal as all our old post permalinks point to the subdomain.
I was therefore wondering if there is a way to use the .htaccess to rewrite domain.com/blog -> blog.domain.com
Any help would be greatly appreciated.
I believe you want to redirect all the traffic from blog.domain.com to domain.com/blog. Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(blog)\.(domain\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [NE,R=302,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I have a URL:
www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space
I want to stay on the same page above but simply display the URL in the address bar like this:
www.example.com/property-listings/united-states/colorado/denver/office-space
How do I accomplish this using htaccess and rewrite rules?
If I understood right, try writing a rule like this one:
RewriteEngine on
RewriteRule property-listings/united-states/colorado/denver/office-space http://www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space [L]
OK. You didn't supply a pattern or mentioned there was any, so I have to guess the pattern is up to /denver/ subdirectory. Try this:
RewriteEngine on
RewriteRule ^(property-listings/united-states/colorado/denver/)(office-space)/?$ $1denver-co-$2 [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(property-listings/united-states/colorado)/(denver)/(office-space)/?$ $1/$2/$2-co-$3 [L,NC]