removing url parameters from one url using .htaccess codes - .htaccess

I tried lot of combinations using available examples (.htaccess directives), but I couldn't able to achieve what I want. The problem is...
My actual URL is
http://localhost/smon2/custsms/index.php?p_mob=9886419001
What I want is
http://localhost/smon2/custsms/
Please help me in wrinting .htaccess code lines.
Thanks
I tried with few of the items below...
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p_mob=1$
RewriteRule (.*) $1? [R=permanent]
RewriteEngine On
RewriteCond %{QUERY_STRING} "p_mob=" [NC]
RewriteRule (.*) /$1? [R=301,L]
RewriteEngine On
RewriteRule ^/custsms/%{QUERY_STRING}/?$ http : //localhost/smon2/custsms/ [NC,L]
Nothing was working. please help.

Replace all your current rules with this rule:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /smon2/
RewriteCond %{QUERY_STRING} ^p_mob=\d+ [NC]
RewriteRule ^(custsms)/index\.php$ $1/? [R=301,L,NC]

Related

I want to redirect query string URL to specific page. adparch.com/*/*pagenumber=* to adparch.com/projects

I got these URLs
https://www.adparch.com/vi/projects/common-wealth-bank/?pagenumber=2
https://www.adparch.com/projects/Technology--It/oppo?pagenumber=2
https://www.adparch.com/vi-VN/ky-thuat-cong-nghe?pagenumber=4
https://www.adparch.com/vi-VN/du-an?pagenumber=8
And They got 1 rule contains characters (?pagenumber). I want to redirect all to https://www.adparch.com/project/
I used .htaccess file for redirecting these URLs
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*$
RewriteCond %{QUERY_STRING} ^pagenumber=(.*)
RewriteRule ^(.*) /project [R=301,L]
But it seems not work.
Thank you so much
I do some cuts in your rules, please check:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} pagenumber=(.*)
RewriteRule ^(.*) /project/? [R=301,L]
</IfModule>

.htaccess redirect with question mark

I'm trying this to redirect via .htaccess a this URL
http://www.deguate.com/foros/showthread.php?874-Soy-de-Guatemala-y-quiero-dar-a-mi-bebe-en-adopcion
to this one:
https://www.deguate.com/artman/publish/mujer-actualidad/Soy-de-Guatemala-quiero-dar-mi-bebe-adopcion.shtml
I've tried many options but nothing seems to work, like:
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^foros\/showthread\.php\?874\-Soy\-de\-Guatemala\-y\-quiero\-dar\-a\-mi\-bebe\-en\-adopcion$ "https\:\/\/www\.deguate\.com\/artman\/publish\/mujer\-actualidad\/Soy\-de\-Guatemala\-quiero\-dar\-mi\-bebe\-adopcion\.shtml" [R=301,L]
You can use the following rule:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(874-Soy-de-Guatemala-y-quiero-dar-a-mi-bebe-en-adopcion)$
RewriteRule ^foros/showthread\.php$ https://www.deguate.com/artman/publish/mujer-actualidad/%1? [L,R]

Friendly Url for .php?id=1

I have this url
www.mysite.com/proyecto.php?id=3
and want this type of url
www.mysite.com/proyecto/id/3
I remember using this kind of code but is not working, any idea please?
<ifModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule proyecto/id/(.*)/ proyecto.php?id=$1
RewriteRule proyecto/id/(.*) proyecto.php?id=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /error404.php
</ifModule>
Finally I improved a bit and I did www.mysite.com/proyecto/1 width the following code in the .htaccess
Thanks for the help!
RewriteEngine On
RewriteRule ^proyecto/([0-9]+)/?$ proyecto.php?id=$1 [NC,L]
Your code sample looks very confusing and does not match your verbal description at all. If I got you right, this is main part you are looking for:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteCond %{REQUEST_URI} !^proyecto/id/(\d+)/? [NC]
RewriteCond %{QUERY_STRING} ^id=(\d+) [NC]
RewriteRule ^.*$ proyecto/id/%1/? [NC,L,R=301]

htaccess 301 redirect query to new domain

trying to redirect this query to a new domain:
www.domain.com/search.php?q=keyword
to
www.newdomain.com/search.php?q=keyword
keyword can be any word
And want to keep the rest in domain, I just need to redirect this query.
I try several ways and the one I found closer to solution is this one:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=1$
RewriteRule ^search\.php$ http://www.newdomain.com/search.php?q=$1 [R=301,L]
but does not work!
Hope someone could help me correcting this and also if this is the best way to do the job?
Many thanks.
You're pretty close.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^(search\.php)$ http://www.newdomain.com/$1 [R=301,L,NC]
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]
this works and is simple
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [QSA]

Issue with subdomains and htaccess for SEO

I would like to change urls from:
http://subdomain.domain.com/page/ to http://subdomain.domain.com/?page=pagename
and also:
http://domain.com/page/ to http://domain.com/?page=pagename
though haven't had much success.
Here is my htaccess file so far [updated]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
I used RewriteRule ^([a-zA-Z]+)/$ ?page=$1 which seemed to work for the domain url but not the subdomain. Any help would be appreciated.
Actually had to do something like this recently. Try this for your Subdomain redirect block:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
Or maybe this; note the change from $2 to $1:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
EDIT: Or Maybe try this. Note that you need to capture two parts of the URL to rewrite as you are explaining. Each item in parenthesis ( and ) corresponds to a string in the rewrite. Try this. Using your nicer regular expression RewriteRule as you mention in the comments:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
So it was an easy fix really. I basically put a .htaccess file in each subdomain directory that looks like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
Hope this helps someone. :D

Resources