Subdomain rewrite help for joomla SEF urls - php

been stuck at this for the past couple of hours here. Let me just illustrate my problem simply by the following lines.
Here's
1) Joomla absolute URL for the page i'm trying to convert: http://classifiedads4free.com/index.php?option=com_adsmanager&view=front
then:
Created menu item and activated SEF urls: So now alias becomes http://classifiedads4free.com/ads
after which:
I added a query string at the back of the URL so it becomes: http://classifiedads4free.com/ads?country=Singapore.
Was just wondering if there's anyway i can make the url at the top http://classifiedads4free.com/ads?country=Singapore. -->http://singapore.classifiedads4free.com
Tried going back to using the absolute URL on my .htaccess file, Following is the code:
1st tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) ads?country=%1 [L]
2nd tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) index.php?option=com_adsmanager&view=front&country=%1 [L]
However, I can't seem to get the redirect working. It keeps redirecting me back to my home page which isn't what i requested.
Would appreciate if someone could provide some assistance here. Been trying all day long.

Try this:
RewriteRule ^(.*)$ http://www.classifiedads4free.com/ads?country=%1 [L,NC]

Related

.htaccess; Too many redirects if two different redirects in .htaccess

I've two types of URLs:
http://www.example.com/?content=contact_form.php
and
http://www.example.com/?content=product.php&id=20
I changed my whole URL system like this:
http://www.example.com/file/contact_form
and
http://www.example.com/product/I-m-the-title/20
Of course I made 301 redirect with .htaccess to tell Google and co. the new URL.
I made it like this:
# Rewrite URLs
RewriteEngine On
RewriteRule ^(ignore)($|/) - [L]
RewriteRule ^file/([^/]*)$ /?content=$1.php [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?content=$1.php&title=$2&id=$3 [L]
# Redirect old URL to new URL
RewriteCond %{QUERY_STRING} ^content=contact\_form\.php$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/file/contact_form? [R=301,L]
RewriteCond %{QUERY_STRING} ^content=product\.php&class=I-m-the-title$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/I-m-the-title/Test/20? [R=301,L]
My problem:
It's perfectly working for: http://www.example.com/?content=product.php&id=20
But for http://www.example.com/?content=contact_form.php I'm getting the message that it couldn't get opened because of too much redirect.
Does anybody know what I'm doing wrong? I hope anybody can help me soon because I have to fix it before Google misinterprets it.
Your rule cause an infinite loop because it is rewriting your uri to the same location again and again overriding your internal and external redirects.. To fix the Rewrite loop, add the following at the top of your htaccess
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

Rewrite rule not working

I'm breaking my head in redirecting a few page from my old asp website to my new php website.
For example, I want to redirect permanently the following 2 pages from my asp website to my php website
1) http://www.mywebsite.com/shopdisplayproducts.asp?id=11&cat=food&sortorder=mostrecent&page=1&pagesize=12
TO
http://www.mywebsite.com/index.php?route=product/category&path=10_11
where 11 should be the link between old and new website to display the correct page.
2) shopexd.asp?id=3903&prod=food&vrnt=green&mrk=studio&cat=11
TO
index.php?route=product/product&path=10_11&product_id=3903
where the number 11 is the link between old and new url for the category and the number 3903 is the link for the product number
I have the following rewrite rule in my htaccess page for the first redirect, but it seems not be triggered. What is wrong? Please help.
RewriteCond %{REQUEST_URI} ^/shopdisplayproducts\.asp\?id=([0-9]+).*$ [NC]
RewriteRule ^shopdisplayproducts\.asp\?id=([0-9]+).*$ index.php?route=product/category&path=10_$1 [R=301,L]
I also tried:
RewriteCond %{REQUEST_URI} ^shopdisplayproducts\.asp\?id=([0-9]+).*$ [NC]
RewriteRule ^shopdisplayproducts\.asp\?id=([0-9]+).*$ index.php?route=product/category&path=10_$1 [R=301,L]
Thanks for any help
Sabko
You need to use QUERY_STRING variable in rule condition:
RewriteEngine On
# /shopexd.asp?id=3903&prod=food&vrnt=green&mrk=studio&cat=11 to
# /index.php?route=product/product&path=10_11&product_id=3903
RewriteCond %{QUERY_STRING} ^id=(\d+)&.*&cat=(\d+) [NC]
RewriteRule ^shopexd\.asp$ /index.php?route=product/category&path=10_%2&product_id=%1 [R=301,NC,L]
RewriteCond %{QUERY_STRING} ^id=(\d+) [NC]
RewriteRule ^shopdisplayproducts\.asp$ /index.php?route=product/category&path=10_%1 [R=301,NC,L]

htaccess subdomain rewrite to variable without being visible in the url

I need to convert "subdomains" to variables using htaccess.
But I don't want the original url to be displayd after the rewrite.
Here's what I have so far:
rewritecond %{http_host} ^([A-Za-z0-9-]+)\.mysite.\com$ [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1?aff=%1 [nc]
But it doesn't seem to work.
What I need is the following:
User links to:
aff1.mysite.com
The displayed url changes to:
www.mysite.com/
But the actual url that the server reads is:
www.mysite.com/?aff=aff1
I'm also going to be adding languages to the mix, so I might even need something like the following:
User links to: aff1.mysite.com
Then I get the language from a cookie {HTTP_COOKIE} lang=([A-Za-z]+)$
If there's nothing in the cookie, the default should be "en"
Then the user gets redirected to aff1.en.mysite.com
Which should then be displayed as: www.mysite.com/en/
but to the server: www.mysite.com/?lang=en&aff=aff1
Please tell me this is possible, and how I can achieve this. I'm very new to rewriting. And I've viewed other questions and tried their solutions, but somehow can't adapt it to exactly what I need.
Also... www.mysite.com shouldn't go to www.mysite.com/aff=www
It should just go to /mysite.com/en/
So, I've spent way more time than I wanted to on this, but finally got something working. Instead of passing the variables in the url, I'm dropping a cookie (which was ultimately what I was doing on the page anyway, but this cuts out a step - and I didn't know that you could drop cookies with the rewrite).
If anyone has a better solution with less lines of code, please feel free to comment or post a new answer.
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{http_host} ^www.example.info [nc] #if url starts with www.example.info
RewriteRule ^(.*)$ http://example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{http_host} ^www.(.*).example.info [nc] #if url starts with www.(aff).example.info
RewriteRule ^(.*)$ http://%1.example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ - [co=aff:%1:example.info:7200:/] #drop/update cookie with aff
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ http://example.info/$1 [nc,R,L] #rewrite without subdomain

Magento multi language rewrites SEO fix?

I have made a website in with Magento in one language 2 years ago and now I would like to add another language.
My actual structure is like that
example.com/category/
example.com/about.html
example.com/product.html
and I would like to obtain a structure like this:
example.com/lang1/category/
example.com/lang1/about.html
example.com/lang1/product.html
example.com/lang2/category/
example.com/lang2/about.html
example.com/lang2/product.html
This is not a big deal since Magento allowes me us to do that simply logging in the backend ->System -> Configuration -> Web -> Add store code to Urls (YES)
I can't do this setting right now because before that I need to fix and do rewrites from the first structure to the new one.
example.com/everything_without_the_/lang1/_path to a permanent
example.com/lang1/everything
I need for example that the urls from the backlinks from posts from the socials and other webistes won't get a 404 error but will automatically be redirected with a 301 redirection to the equivalent page in the new structure.
So I would like to add a script like this in the natural language:
rewrite permanently all the urls which ends not with /lang1/ or /lang2/ to urls with the prefix /lang1/
I know that I could manually add rewrite rules with this schema in the Magento backend but I would prefer to know if it is possible to batch this directly from the database or with some script in the .htaccess or index.php and above all which one between these solutions will have a less negative impact in SEO and SERP.
I've found a solution
Hi I've found a solution:
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteRule ^(/)?$ it/index.php [L]
at a first look works, but I not guarantee.
I hope this will help
Cheers
Try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/lang1/
RewriteCond %{REQUEST_URI} !(.*)/lang2/
RewriteRule ^(.*)$ http://www.domain.com/$1/lang1/ [R=301,L]
you can use .htaccess 301 url to make if possible with your own regex function
As you need some specific requirement to do with your language part
here i am giving you category example
Redirecting Subcategory URL with New Parent URL
Examples:
category/sub1 redirect to cat/sub1
category/sub2 redirect to cat/sub2
category/sub3 redirect to cat/sub3
This may be needed if you changed a parent Category URL or even if you want to remove the parent URL completely:
RewriteRule ^category/(.*) http://www.yourwebsite.com/cat/$1 [R=301, L]
OR to remove '/category/' completely from yourwebsite.com/category/sub and end up with yourwebsite.com/sub ('sub' can be any url):
RewriteRule ^category/(.*) http://www.yourwebsite.com/$1/ [R=301, L]
And also you can refer
http://www.learnmagento.org/magento-tutorials/301-redirects-in-magento/
http://blog.maximusbusiness.com/2012/10/magento-url-rewriting-regex-and-301-redirects-tips/
hope this will sure help you.
I've found a solution
Hi I've found a solution:
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteRule ^(/)?$ it/index.php [L]
at a first look works, but I not guarantee. I hope this will help Cheers

.htaccess problem, need to add string to certain URL's

In my infinity stupidity I changed the permalinks on my wordpress blog a little while back and have now changed them again. The problem that I have now caused is that I have a few hundred URL's out there which no longer work.
For example this URL looks like the ones that used to work
http://www.lazygamer.net/the-evopoints-co-za-downloads-of-the-week-1305/
But you'll see that just gives you a 404 not found page now because my site expects the first subdirectory to be a category such as
http://www.lazygamer.net/xbox-360/the-evopoints-co-za-downloads-of-the-week-1305/
So now I want to put a htaccess rule in that checks to see if a category exists and if it doesn't then just add in something random to make the url resolve.
I'm pretty sure I can do this with a regular expression of sorts but I can't figure it out.
[Update] My current .htaccess file
RewriteEngine On
RewriteBase /
RewriteRule ^/([^/]+)/$ /category/$1/ [R]
RewriteRule ^index\.php$ - [L]
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^lazygamer\.net$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]
Read up mod_rewrite to understand how to use these for other problems!
RewriteRule ^/([^/]+)/$ /category/$1/ [R]
That should do it.
Beware, this will redirect anything with one directory path in the URL to /category/{original_url_path}

Categories