Rewrite URL through .htaccess - .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]

Related

Rewrite url via htaccess on apache server

I have a url which is
www.domain.com/index.php?route=ticketsystem/generatetickets
I want people who type in the url www.domain.com/contact to be redirected to the page index.php?route=ticketsystem/generatetickets however have the url bar still show /contact is that possible via htaccess and if so how? I tried the below
RewriteEngine On
RewriteBase /
RewriteRule contact /index.php?route=ticketsystem/generatetickets [L,QSA]
For your shown attempts, please try following .htaccess rules file. Make sure your index.php and .htaccess files are present in same directory/folder. Also better to use & rather than using / for query string.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^contact/?$ index.php?route=ticketsystem&generatetickets [QSA,NC,L]

htaccess code to encode URLs with different page name

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.

URL Rewriting in. Htaccess

I have a website on a test server and I want to rewrite URL for this website because it is very long
I wish our visitors instead of entering this URL:
http://staging.company.fr/site2.it/s...oject2/public/
enter this URL:
www.monsite.com
I created a file. htaccess:
RewriteEngine On
RewriteRule ^/~(.+) http://www.monsite.com/~$1 [NC,L]
but does not work
While in .htaccess mod_rewrite doesn't match leading slash in a URL since it is applied per directory. Therefore following should work:
RewriteEngine On
RewriteRule ^(.+)$ http://www.monsite.com/$1 [L,R=301,NE]
This will redirect every URL in your existing domain other than home / to monsite.com
Reference: Apache mod_rewrite Introduction

.htaccess redirect non existing pages based on index.php page with wildcard and something after it to index.php

Please help, some website is arbitrarily adding dynamic query strings to my home page.
For example my home page is www.mysite.com/index.php and they link to many links like this:
www.mysite.com/index.php?a=something-something-something
www.mysite.com/index.php?a=something-other
www.mysite.com/index.php?a=some-other-thing
And those links are opening on my site, content of page are the same for every page, just like my original www.mysite.com/index.php
There are few hundreds of that links pointing to my site. So how I can redirect this:
www.mysite.com/index.php?a=something-something-something
www.mysite.com/index.php?a=something-other
www.mysite.com/index.php?a=some-other-thing
...
to
www.mysite.com/index.php or just to www.mysite.com/
This what I tried so far in my .htaccess file
RedirectMatch 302 ^index.php?a= http://www.www.example-ste.com/
RewriteRule ^/index.php?a=(.*) http://www.example-ste.com/
But still pages are opening on site.
Another similar question.
How to redirect pages ending with "?pagewanted=all" to the same page but with out that "?pagewanted=all"
For example I need to redirect page:
www.mysite.com/something-something/something.html?pagewanted=all
to
www.mysite.com/something-something/something.html
Hello.
I just noticed something. I needed URL redirection rule which will redirect pages like:
www.mysite.com/index.php?a=something-something-something
www.mysite.com/index.php?a=something-other
www.mysite.com/index.php?a=some-other-thing
to home page of site, root. And you gave me this code:
RewriteEngine On
RewriteBase /
#if the query string has an a parameter
RewriteCond %{QUERY_STRING} (^|&)a= [NC]
#Redirect and remove query string parameters
RewriteRule .* http://www.mysite.com/? [R=301,L]
And I must say it works fine, it does that, but I just noticed that it somehow blocks or redirect all links containing ?a= for example on some temporary pages I have links like:
i.php?a=something-something-something
So, can you adopt code just for pages based on index.php like:
www.mysite.com/index.php?a=something-something-something
and not for links with:
i.php?a=something-something-something
If I am right it works on all links with "a=" but I need just for "index.php?a="
Try adding the folloginw to the top of your .htaccess file
RewriteEngine On
RewriteBase /
#if the query string has an a parameter
RewriteCond %{QUERY_STRING} (^|&)a= [NC]
#Redirect and remove query string parameters
RewriteRule .* http://www.mysite.com/? [R=301,L]
#if the query string has a pagewanted parameter
RewriteCond %{QUERY_STRING} (^|&)pagewanted=all [NC]
#Redirect and remove query string parameters for html pages
RewriteRule (.+\.html) http://www.mysite.com/$1? [R=301,L]
Edit.
Added rule to remove pagewanted=all

Redirect hundreds of urls with htaccess

hello my url structure right now for the majority of my links is:
www.url.com/category1/sample-keyword.html
I am looking to redirect them to the new url that has dropped the word sample from the url structure ie to this:
www.url.com/category1/keyword.html
what should i put in htaccess that auto redirects all the urls in the www.url.com/category1/ section to redirect to the new url structure?
This should do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*/)sample-(.*)$ $1$2 [L,R=301]
It will match all URLS with the substring /sample- and strip it from the URL. Depending on your site organization, you may need to adjust the pattern, but that should be a good jumping-off point.
RewriteEngine On
# Redirect sample-*.html to *.html
RewriteRule ^\/?category([0-9]+)\/sample\-([^\/]+)\.html$ http://www.url.com/category$1/$2.html [R=301]
# Serve *.html
RewriteRule ^\/?category([0-9]+)\/([^\/]+)\.html$ page.php?category_id=$1&keyword=$2 [L]

Resources