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.
Related
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]
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]
I'd like to rewrite part of URLS like:
http://www.myweb.com/cat1/subcat2/how-to-do-this
to
http://www.myweb.com/cat2/subcat2/how-to-do-this
there are many urls in which the end part(how-to-do-this) changes
I have tried this:
RewriteRule ^cat1/subcat1/(.*) /cat/subcat2 [R=301,L,NC]
but this doesn't works.
Please help.
R=301 is used for external redirection, if you want to rewrite the request , you can use the following :
RewriteRule ^cat1/subcat2/(.*) /cat2/subcat2/$1 [L,NC]
This will internally redirect (without changing the url in browser)
cat1/subcat2/foo
to
cat2/subcat2/foo
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.
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_.