htaccess remove the duplicate names in the urls - .htaccess

I have this page and if you scroll to the middle of the page you will see many links that all have duplicate names like for example
http://healingstreamsusa.org/healing/healing/good-grief.html
http://healingstreamsusa.org/healing/healing/forgiveness-not-option.html
As you can see there are two healing/healing instead of the one healing/ so the urls are all breaking and there are many sitewide...The client made all the urls relative instead of absolute and now he needs an htaccess that will remove the duplicates in the middle....here is what i have and its doesnt do the redirect as i expected....am i missing something
RewriteCond %(REQUEST_URI) ^/healing/healing[/]?
RewriteRule (.*) http://healingstreamsusa.org/healing? [R=301,L]
Tried all these.....
RewriteRule /about/about/(.+)$ /about/$1 [R=301]
RewriteRule /about/images/(.+)$ /images/$1 [R=301]
RewriteRule /healing/images/stories/(.+)$ /images/stories/$1 [R=301]
RewriteRule /healing/healing/(.+)$ /healing/$1 [R=301]
RewriteRule ^healing/healing/([^/]*)$ /healing/$1
Any idea why this would not work....

RewriteEngine On
RewriteRule ^healing/healing/([^/]*)$ healing/$1
RewriteRule ^about/about/([^/]*) about/$1

Related

.htaccess redirects with multiple paramenters

I am rebuilding a real estate site and we have completely restructured how the database handles the properties and I am now trying to redirect all of the old property urls to the new ones. The problem that I am having is that the old urls used multiple parameters(including the section and the property id) for a single property and the new urls only use a slug for the property name.
Example:
OLD: https://www.example.com/listings.php?sect=1&view=92
NEW: https://www.example.com/listings/tombstone-ranch
My current .htaccess looks like the following with the last two lines being the rewrites for converting the slugs into clean urls...all of this works fine.
RewriteEngine On
RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteRule ^listings/([a-zA-Z0-9-/]+)$ /listings/index.php?s=$1 [L]
RewriteRule ^listings/([a-zA-Z0-9-/]+)/$ /listings/index.php?s=$1 [L]
The Problem that I am having is that neither of the following seems to work:
Redirect 301 /listings.php?sect=1&view=92 /listings/tombstone-ranch
and neither does this:
RewriteRule ^listings.php?sect=3&view=33 /listings/tombstone-ranch
or any other variations that I have tried.
Any thoughts? .htaccess is not my strong suit and unfortuinately I need to get these to work considering the old version of the site and it's urls have been around for almost 8 years now so there is the potential for dead links on about 75 properties.
Could you try this rule. Can't test it at the moment.
RewriteCond %{QUERY_STRING} sect=1&view=92
RewriteRule ^listings\.php$ /listings/thombstone-ranch/? [L,R=301]
Also the rule you added will not work because you must add a backslash
Wrong:
RewriteRule ^listings.php?sect=3&view=33 /listings/tombstone-ranch
Right:
RewriteRule ^listings\.php?sect=3&view=33 /listings/tombstone-ranch
Don't forget since your main URL is a query, you should use the first option that I gave to you. If that doesn't work leave a comment and I'll be glad to help you out

How do I redirect old ugly looking urls to new SEO friendly urls?

I really need some help figuring this out since I've been trying to solve this problem for couple of days already.
I had old urls that looked like this:
category.php?id=6&name=maxi-dresses&type=1**
I have changed them to look like this using htaccess: https://markandroberts.com/category/dresses/maxi-dresses/
As you can noticed, in the new urls I have also changed the position of the category id by putting it at the end instead at the beginning.
What I want to do now is to 301 redirect all the old category urls that are already indexed in Google to the new location.
Here's my current htaccess code:
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.markandroberts.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^product/([0-9]+)/(.*)/(.*)/$^ product.php?id=$1&type=$2&name=$3
RewriteRule ^product/([0-9]+)/(.*)/(.*)/ product.php?id=$1&type=$2&name=$3
RewriteRule ^category/(.*)/(.*)/$^ category.php?type=$1&id=$2
RewriteRule ^category/(.*)/(.*)/ category.php?type=$1&id=$2
RewriteRule ^type/(.*)$/^ main-category.php?maincat=$1
RewriteRule ^type/(.*)/ main-category.php?maincat=$1
RedirectMatch 301 /category.php?id=$1&name=$2&type=$3 /category/$3/$1/
Any solutions that work?
You need to modify your .htaccess file to include some "pretty url" rules. Here is an example for you.

.htaccess rewriting url from subdirectory

I have entries in my .htaccess that goes like this:
RewriteRule ^$ dubai/ [R]
RewriteRule ^dubai/$ page/index.php [L]
RewriteRule ^$ pakistan/ [R]
RewriteRule ^pakistan/$ page/index.php [L]
basically I want to make a rule that can handle countries as part of the rewrite, the above code i have is redundant and can cause the file to grow unnecessarily.
Is there a way to automatically redirect the page to page/index.php if it serves for any countries? I tried putting this line to the last line above:
RewriteRule ^([a-zA-Z\/]*)/$ page/index.php
My problem is it no longer reads the succeeding rules for the other pages to serve. The below lines are samples of the rules just below the last one above:
RewriteRule ^([a-zA-Z\/]*)rent/$ page/index.php?methodcall=rent&for=Rent
RewriteRule ^([a-zA-Z\/]*)landlords/$ page/index.php?methodcall=landlords
What happens is the get vars are no longer read by index.php file, if i remove the last rewriterule the key vars are read properly.
Any suggestions?
Thanks in advance!
Try this:
RewriteEngine on
RewriteRule ^([a-z]+)(\/?)$ page/index.php [NC,QSA,L]
RewriteRule ^([a-z]+)/rent(\/?)$ page/index.php?methodcall=rent&for=Rent [NC,QSA,L]
RewriteRule ^([a-z]+)/landlords(\/?)$ page/index.php?methodcall=landlords [NC,QSA,L]

Remove subdirectory & remove .php extention in htaccess not working?

I m new to url rewrite:
First, here is what I am trying to accomplish:
Current URL: www.example.com/subdirectory1/subdirectory2/something.php
Desired URL: www.example.com/subdirectory1/something/
And, the name of subdirectory2 is fixed.
Possible?
My current htaccess just to remove the ".php" but also not working. (Any idea how to debug htaccess??)
RewritEngine on
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(?!subdirectory1/|subdirectory2/)(.+)$ subdirectory1/$1 [L]
Thanks.
Your first problem is RewritEngine on. You are missing an e. Should be RewriteEngine on.
Try this:
RewriteEngine on
# Remove .php
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^([^/]+)/fixed/([^/]+).php$ /$1/$2/ [R=301,L]
# Rewrite "friendly" URL into php.
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/fixed/$2.php [L]
This only works for exactly what you said. Fixed is always the same. Replace it with the correct value.
The users goes to: www.example.com/1234/fixed/5678.php. He is redirected to www.example.com/1234/5678
User goes to www.example.com/1234/5678. On the server, this becomes www.example.com/1234/fixed/5678.php.
Something like www.example.com/1234/5678/9abcd will not work. (More than two levels of directories.)

.htaccess mod_rewrite playing with variables

I want to have my site urls look like
http://example.com/place/info?var=info&morevars=ifneeded
Place and info are also variables but they have a fixed name, the ones after would vary. EDIT This is the url I am trying to rewrite
http://example.com/test.php?place=test&action=info&var=info&morevars=ifneeded
This is what I have so far
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC]
I think there a way to do this with {QUERY_STRING} but I can't get it to work just 500 errors or it don't make a differences.
You have set the QSA flag that automatically appends the original requested query to the new one:
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC,QSA]
You're missing the first /
RewriteEngine on
RewriteRule ^/([A-Za-z0-9-]+)/ test2.php?place=$1 [NC]
RewriteRule ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ test2.php?place=$1&action=$2 [NC]

Resources