rewrite engine is removing slashes from my urls - apache

I have looked everywhere and spent hours trying to get this working, but I have been unsuccessful. I could really use some help.
I am not an expert with apache but I have an old URL and am trying to redirect all my old pages to my new URL. My old URL is:
www.bc-mortgage-brokers.ca
My new URL is
http://bc-mortgage-broker.ca
The home page redirects correctly, but it is the only one to do so. For example, if I type:
www.bc-mortgage-brokers.ca/16/
into my browswer, it removes the slashes and then fails to redirect. I will get this url instead:
bc-mortgage-broker.ca16
in my .htaccess file, I have the entry for this particular one as:
redirect 301 /16/ http://bc-mortgage-broker.ca/16/
My header for the file is currently:
Options +FollowSymLinks
RewriteEngine on
I am creating the file in textmate.
When I look at the error logs, I read:
RewriteCond: bad flag delimiters

Use this rule in your root .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(16(?:/.*)?)$ http://bc-mortgage-broker.ca/$1 [L,R=301]

Related

301 redirect urls with a slash in querystring

We built a new webshop for one of our clients, and are 301 redirecting their old url's to our normal ones. As usual we do this using .htaccess as follows:
Redirect 301 /url1/ http://www.url2.com/ and it works fine.
BUT the old shop has this querystring with slashes in it (!) , for example:
/epages/14353.sf/de_DE/?ObjectPath=/Shops/61922345/Products/32428
And as soon as I use this in a htaccess 301 redirect string it stops working. I don't get a 500 error or something like that, but when I visit /epages/14353.sf/de_DE/?ObjectPath=/Shops/61922345/Products/32428 it won't redirect. If I would use it with a querystring like the following (/epages/14353.sf/de_DE/?ObjectPath=foobar) I can visit it and get redirected, but not if there's a slash in it.
I tried backslashing it, encoding etc. but without the right results. Does any1 have an idea? I tried AllowEncodedSlashes On but it gave me a 500 error.
Since you cannot match QUERY_STRING in Redirect directive, you need to use mod_rewrite based rule.
Have this one in your root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} ObjectPath=/Shops/61922345/Products/32428
RewriteRule ^/?epages/14353\.sf/de_DE/?$ https://www.nu.nl? [L,NC,R=301]
Make sure to test this in a new browser to avoid old cached data.

.htaccess redirecting only pages with no subfolder

I am using .htaccess to redirect pages from an old website to a new site. The URL structure has changed completely, but thanks to a SEO person I have a complete list of URLs I have to redirect and take care of.
My .htaccess looks like the following:
Options +FollowSymlinks
RewriteEngine On
Redirect 301 /some-guy http://www.new.domain/kontakt/
Redirect 301 /some-other-guy http://www.new.domain/kontakt/
...
Redirect 301 /de/some-page http://www.new.domain/some/subpage/
Redirect 301 /de/another/page http://www.new.domain/nice-page/
Of course the URLs can be even longer and contain query strings and stuff like that. The new website has a different URL structure and does not need query strings and nothing.
Now, while the first two redirects work perfectly, every redirect which contains a subfolder fails to redirect to the target location. The last URL for example redirects to
http://www.new.domain/de/another/page
What am I missing here?
Try
Redirect 301 ^de/another/page http://www.new.domain/nice-page [L]
I got it working now with little modifications to Anup Saunds code (and therefore using mod_rewrite).
I used the following structure which seems to work fine with all links I have and sets the status code for search engines.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^what/ever/your/path-is(.*)$ http://www.new.domain/oh-what/a-nice-path/ [R=301,nc]

Clean URL not working properly

Hey I'm struggling with this all day long and I'm new to clean URLs.
My Domain which i want to change:
http://www.domain.tld/ausflug.php?lang=de
to:
http://www.domain.tld/ausflug/lang/de/
via .htaccess. This is my code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ausflug/lang/(.*)/ ausflug.php?lang=$1
My Problems are:
If I navigate through my page, the url still is the ugly one.
And if I want to reach the page with the clean url, it won't display all the
css and js stuff.
Thanks for help!
First of all, replace your current code by this one (your htaccess should be in root folder)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/ausflug\.php\?lang=([a-z]{2}) [NC]
RewriteRule . /ausflug/lang/%1/? [R=301,L]
RewriteRule ^ausflug/lang/([a-z]{2})/$ /ausflug.php?lang=$1 [L]
This will redirect domain.tld/ausflug.php?lang=de to domain.tld/ausflug/lang/de/ and will internally rewrite it (without any redirection loop error) to domain.tld/ausflug.php?lang=de.
For your second problem:
if I want to reach the page with the clean url, it won't display all
the css and js stuff
Simply use absolute paths for your links (with a leading slash).
Example: /css/file.css instead of css/file.css (otherwise it will look in wrong directory, since your rule is generating some virtual directories)
Or you can add this html tag <base href="/"> right after <head> in all pages (instead of replacing each links)

mod_rewrite 404 error trying to rewrite URL

I have website that is using unfriendly URLs and I want to change them using mod_rewrite.
I have a URL like this:
http://www.website.nl/?p=2
and I want it to be
http://www.website.nl/about-us
When I use this on my local server it works correct but on the live webserver it doesnt
I use this code in my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^about-us$ /?p=2 [L]
I already checked if mod_rewrite is enabled and in my apache2handler it is enabled so it should work shouldn't it?
What am I missing or doing wrong?
You may be missing the leading / (forward slash) in your pattern, try:
RewriteRule ^/about-us$ /?p=2 [L]

Redirect complete url to another url

Actually i have changed my dynamic urls to static urls. But the strange thing is i have some old urls which are dynamic. Among them the url is http://www.startonlinegames.com/download.php . I want this url to redirect to http://www.startonlinegames.com/download/?page=download .. for this i have added the following htaccess rule in my htaccess file.
Redirect http://www.startonlinegames.com/download.php http://www.startonlinegames.com/download/?page=download
but its not working...can anyone suggest me.
Try this : and let me know if it works otherwise will try for another
Options +FollowSymlinks
RewriteEngine on
rewriterule ^download.php(.*)$ http://www.startonlinegames.com/download/?page=download$1 [r=301,nc]