Url rewriting in .htaccess file in Joomla Site - .htaccess

I want to write a rule in .htaccess file, all I want to do it:
The user will look for following link:
www.example.com/sitemap.xml (in browser address bar)
but in reality I want to show the following link:
www.example.com/index.php?option=com_xmap&view=xml

Try this
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/sitemap\.xml$
RewriteRule .* /index.php?option=com_xmap&view=xml [QSA,R,L]

You need to use mod_rewrite. There are lots of details in the official docs. If you don't want the user to see the new URL in the address bar, you should use an internal redirect.
RewriteEngine on
RewriteRule "^/sitemap\.xml$" "/index.php?option=com_xmap&view=xml" [PT]

Related

.htaccess - Redirect all .html capture the ID

I am facing the following problem:
I have a website in which the URLS currently look like:
/manufacturer/product/[ID].html
I have re-developed the website (Using Laravel) and now it just is:
/product/[ID]
I am wondering whether it is possible to use a .htaccess file to redirect all these links back to the new link? So, in essence, I would need to just capture the [ID] from the old link and redirect it back to the new link.
EDIT:
So the link will look something like this:
mysite.com/parts/apple/A-6-H0.htm
OR
mysite.com/microsoft/A-1-5F.htm
So both Apple, Microsoft and A- can change depending on what manufacturer and what the product is Does this make sense?
RewriteEngine On
RewriteRule ^parts/(?:[^/]+/)?(.*)\.html?$ /parts/$1/ [R=301,L]
That should take care of it.
Please Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^{domain name}[nc]
RewriteRule ^(.*)$ {domain name}/$1 [r=301,nc]
Redirect 301 /manufacturer/product/$1.html product/$1.html

Redirect user to new link without their knowledge

I wanted implement this using .htaccess file. In my page I have a link to link1. When user clicks, I want them to show another page link2. But I want browser url to continue showing link1.
I have found many similar questions here. But I am unable to implement them because of my lack of knowledge about mod_rewrite.
Try this in your Root/.htaccess file
RewriteEngine on
RewriteBase /
RewriteRule ^link1\.php/?$ /link2.php [L,NC]
This will internally redirect the /link1.php to /link2.php , and your browser will remain at the /link1.php .
You simply don't provide the [R] (redirect) option.
RewriteRule ^link1$ link2 [L,NC]
If you want to redirect silently to another domain, you can use the [P] option if you have mod_proxy and mod_proxy_http installed.
RewriteRule ^link1$ http://example.com/link2 [L,P]

Redirect old page to new page use htaccess

I have new Content Management System which rewrite old static code.
I want to redirect some old page to some new page, for example I want to redirect 3 pages only to 3 new pages:
domain.com/oldpage1 => domain.com/new/newpage1
domain.com/oldpage2 => domain.com/new/newpage2
domain.com/oldpage3 => domain.com/new/newpage3
how to do it with .htaccess?
You can use mod_rewrite for stuff like that. Have a look here:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
There are many possibilities and the exact commands depend on your link structure, but in principle (assuming that its about redirecting domain.com/mypageto domain.com/new/mypage) it works like that in your .htaccess:
RewriteEngine On
RewriteRule ^$ /new [L]
Edit: Of course you will have to install / activate Apaches mod_rewrite beforehand if its not already enabled.
This should be fairly simple. Use these 3 rules in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^oldpage1/?$ /new/newpage1 [L,NC,R=301]
RewriteRule ^oldpage2/?$ /new/newpage2 [L,NC,R=301]
RewriteRule ^oldpage3/?$ /new/newpage3 [L,NC,R=301]

How do I rewrite the url?

Could someone tell me how to rewrite this URL. I have looked at a lot of questions on stackoverflow but they seem to be missing my answer.
RewriteEngine On
That is what I have... its a bit poor.
I need to rewrite url's if they do not point to a directory.
I need to do this...
any.domain.com/pages/some-page-slug/login
To be rewritten to the correct url of...
any.domain.com/pages/login.php?page=32
Does anyone have any ideas on how this can be achieved?
1) Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1
TO do this you need to write a front controller.
See here, here, here, and here.
Alternatively in Apache you can rewrite this
any.domain.com/pages/32/login
or this:
any.domain.com/32/login
or even this:
any.domain.com/some-slug/32/login
to this:
any.domain.com/pages/login.php?page=32
One way or another to do this with only apache you need to supply the page id in some fashion. Keep in mind even with format any.domain.com/some-slug/32/login the content of the slug is irrelevant and won't necessarily link to the correct page. Which I imagine is undesirable and bad for SEO.
Another alternative is using RewriteMap. But this will be tricky and require reloading apache configurations whenever a page/slug is created/edit.
I understand that pages and login are static in this case and some-page-slug is changing. And you always want to redirect to static page /pages/login.php?page=32
So this is how to do it:
1) Rewrite
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32
or 2) Redirect Pernament
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=301,L]
or 3) Redirect Temporary
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=302,L]
Here is great article about htaccess trics
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/

.htaccess 301 redirect path and all child-paths

I want accesses to e.g. www.thisdomain.com/docs/path1/path2 to redirect to www.thatdomain.com/path1/path2
(Note that docs is not a part of the new path)
I have the following on www.thisdomain.com:
RewriteEngine on
RewriteRule ^docs/* http://www.domain.com/ [R=301,L]
If I access www.thisdomain.com/docs, it directs to www.thatdomain.com, but if I access a child-path like www.thisdomain.com/docs/path1/path2 it fails. Is it possible for the redirect to intercept the child-path access and redirect as I need? If so, any pointers?
Thanks.
With regular expressions, * means any number of the previous atom, which will match /docs and /docs/. Try this:
RewriteEngine on
RewriteRule ^docs$ http://www.domain.com/ [R=301,L,QSA]
RewriteRule ^docs/(.*) http://www.domain.com/$1 [R=301,L,QSA]
(QSA is query string append, so /docs/foo?bar=baz won't lose the ?bar=baz.)
According to section "Redirect Old domain to New domain using htaccess redirect" of the first Google result which I found searching for "htaccess redirect" (without the double quotes), this piece of code will suffice:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
According to their description of the technique, it will redirect the directory the .htaccess file is placed in recursively (including any child paths), just as you intend. Of course, mod_rewrite needs to be present for the rewrite directives to work.

Resources