htaccess code to encode URLs with different page name - .htaccess

the below htaccess code work for single URL with same page
RewriteRule ^([^/]*)\.html$ /current/shoppe/sub-category.php?category=$1 [L]
now, i need to rewrite a URL of another page.

Related

Rewrite Rule for Masking the URL with Query string and Page number

I am trying to mask the following url with any page number using htaccess.
https://sampledomain.com/?page=2
to
https://sampledomain.com/page/2
So if we call https://sampledomain.com/page/2 url in the website, internally path should always be calling https://sampledomain.com/?page=2 url
Please suggest me the correct htaccess rule.
In htaccess in your document root, use the following rule :
RewriteEngine on
RewriteRule ^page/([0-9]+)/?$ /?page=$1 [QSA,L]

Rewrite URL through .htaccess

My website generates page URL with the prefix ?Script=, which is not SEO-friendly.
I want to remove this prefix and just keep the page title.
For example, I want to convert the following URL:
example.com/?Script=about to example.com/about
about is the About page of my website.
I want to set up a rule for omitting ?Script= for all pages.
I have managed to do it for my blog post by using the following rewrite rule.
RewriteRule ^news/([0-9a-zA-Z_-]+) ?Script=news_view&uid=$1
This should work for you .
RewriteEngine on
RewriteRule ^(about)/?$ /?script?=$1 [L]
If you have more pages , you can add those pages to the pattern
RewriteEngine on
RewriteRule ^(about|page2|page3)/?$ /?script?=$1 [L]

htaccess mod-rewrite

I'm having trouble with url rewriting. I have the following rule working fine:
RewriteRule ^([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=$1&pg=$2 [L]
which displays the url as follows:
domain.com/theme/pg
What i need is for the the url to rewrite to domain.com/theme#pg I thought the below would work, but it doesn't:
RewriteRule ^([^/\.]+)/?#([^/\.]+)/?$ page.php?theme=$1&pg=$2 [L]
What am I doing wrong?
# in the URL is the client-side thing - you should not get that on the server at all. You can rewrite to the URL containing an anchor, as given e.g. here:
Page anchor with mod_rewrite?
mod_rewrite with anchor link
but not from the URL containing a # - that would not get to the server at all.

strip utm_source from url by htaccess then redirect to origin url

I have issues with URLs of website.
I have check the server and referrers, then see a lot of strange URLs with some addition var added to original. That may effect the SEO and server load to create those pages.
eg:
Original:
xaluan.com/modules.php?name=News&file=article&sid=123456
xaluan.com/modules.php?name=News&file=article&sid=123987
Someone access my web page by url
xaluan.com/modules.php?name=News&file=article&sid=123456&utm_source=twitterfeed&utm_medium=twitter
xaluan.com/modules.php?name=News&file=article&sid=123987&utm_source=twitterfeed&utm_medium=twitter
I need one .htaccess that can redirect all 301 URLs which have utm_source=twitterfeed&utm_medium=twitter to original one.
You could try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^((.*?)&|)utm_
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?%2 [R=301,NE,L]
It will drop everything from the Querystring after the first utm_.

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/

Resources