How to redirect to page number? HTACCESS - .htaccess

this is what I currently have:
http://www.example.com/main?page=2
http://www.example.com/query?page=5
http://www.example.com/archives?page=2
And I want to replace it with:
http://www.example.com/main/2
http://www.example.com/query/5
http://www.example.com/archives/2
But I still want to have $_GET['page'] :)
How to do it with htaccess?

In the htaccess file in your document root, add these rules (preferably above any routing rules that you may have):
RewriteEngine On
RewriteRule ^(.*)/([0-9]+)$ /$1?page=$2 [L]

Related

How to change specific part of my urls to change language editing .htaccess

I want to redirect all urls which includes /en with /de
for example redirect http://www.example.com/en/about/ to http://www.example.com/de/about/
You can try below rule in your .htaccess file:
RewriteRule ^en/(.*)$ /de/$1 [R=301,L]
Read the mod_rewrite manual for redirecting and rewriting URLs.
Reference : https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

How to rewrite with wildcards in htaccess?

How can I rewrite this:
www.mydomain.com/directoryname/(wildcard)
to this:
www.myotherdomain.com/directoryname/(wildcard)
I have many subdirectories and files on the "myotherdomain.com domain name, and I need those to be accessible via the mydomain.com wildcard. I assume I will need to use htaccess to achieve this, but have not bee able to figure out the correct syntax.
Try adding these rules to the htaccess file in the document root of the www.mydomain.com site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^directoryname/(.*)$ http://www.myotherdomain.com/directoryname/$1 [L,R]
That will redirect the browser, which means the address in the URL changes. If you don't want it to change, then you need to have mod_proxy loaded, and change the R to a P. If mod_proxy isn't loaded, then the P flag won't work.

.htaccess rewrite from subdirectory

Any help with this would really be appreciated.
I am setting up 301 redirects in a .htaccess file to redirect hundreds of old urls to the latest live pages.
My .htaccess file is currently located in the root of the domain and looks something like this:
RewriteCond %{QUERY_STRING} ^pName=product-one$ [OR]
RewriteCond %{QUERY_STRING} ^pName=product-two$ [OR]
RewriteCond %{QUERY_STRING} ^pName=completely-different-name$
RewriteRule ^catalog/product_info.php$ http://www.mydomain.com/new-product-name-p-123.html? [R=301,L]
While researching for answers on how to bulk redirect to one url using .htaccess, I read that it would wise to change the location of the .htaccess file and place it in the specific directories to which it apply's, so requests to other directories won't even these rules.
So I have placed the .htaccess file in the specific sub directory, which is catalog, but the redirect no longer works. What am I missing here? I want the rules for the urls to be redirected to be placed in the .htaccess file inside the catalog folder so all those rewrite rules wont be loaded each time the root .htaccess is loaded.
I would suggest you change your redirect 301 line to contain the path directly to you catalog folder of OSCommerce.
So instead of using
RewriteRule ^catalog/product_info.php$ http://www.mydomain.com/new-product-name-p-123.html? [R=301,L]
use e.g.:
Redirect 301 /website/catalog http://www.mydomain.com/page2.htm
or
Redirect 301 /catalog http://www.mydomain.com/page2.htm
Option 1) is if your catalog is located at http://youdDomain.com/website/catalog/ .
If it is located at http://youdDomain.com/website/aaa/catalog/ you would use:
Redirect 301 /website/aaa/catalog http://www.mydomain.com/page2.htm
I tested this in my own webserver - hope it helps.
When you put the .htaccess in a subdirectory, you must adjust the RewriteRule pattern accordingly. mod_rewrite strips the directory prefix, where the .htaccess file is located, see RewriteRule - What is matched?.
You must change the rule to
RewriteRule ^product_info.php$ ...
If you have lots of URL paths to rewrite, you might also want to look into RewriteMap.

htaccess redirection for joomla page

How to do an htaccess redirection for the following
http://goozga.com/demo/index.php?option=com_content&view=article&id=70
needs to rewrite the above URL to
http://goozga.com/demo/index.php?option=com_content&view=article&id=73
please help me?
Try something like:
RewriteCond %{QUERY_STRING} option=com_content&view=article&id=70$
RewriteRule .* index.php?option=com_content&view=article&id=73 [L]
Note that your question has nothing to do with Joomla but depends on Apache's mod_rewrite instead.
Within Joomla, you can also use the Redirect component. You would just have to add a new redirect rule with the first URL as the source and the second as the destination URL.

.htaccess redirects : posting the subsequent uri

I have a website set up where I store all my user profiles in /member-centre/member-directory/USERNAME
My problem is that a number of referrals are posting to a depreciated structure of /members/USERNAME
Is there a way I can configure my .htaccess file to automatically post the requested USERNAME to the correct location? All i've found on google is static redirection.
If this is not possible through .htaccess, is there another method I could use?
Many thanks in advance
If you are looking for a redirect solution, Jon Lin's will work fine. If you want to do a rewrite then put the following in your .htaccess file in the root of your domain
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/members/([^/]+)$ [NC]
RewriteRule . member-centre/member-directory/%1 [L]
if member/centre etc is relative to the root filesystem and not your domain then replace the last line with (just leading slash)
RewriteRule . /member-centre/member-directory/%1 [L]
Do you mean something like:
RedirectMatch 301 ^/members/([^/]+)/? /member-centre/member-directory/$1
This redirects the browser with a permanent redirect.
Try something like this:
RewriteRule ^members/ /member-centre/member-directory/ [L]

Resources