.htaccess baseurl -> mywebshop.nl/shop/baseurl-extension - .htaccess

Currently i'm working on a webshop.
The code for this webshop is stored at 1 single point.
I pointed 800 domainnames that I need to point to the location of my webshop.
This webshop is selling domainnames
So for example. My store is located on: www.mystore.com
I've a pointer from www.foobar.com
This is the function I need (works)
RewriteEngine On
rewritecond %{http_host} ^foobar.com
rewriteRule ^(.*) http://www.mystore.com/shop/foobar-com/$1 [R=301,L]
As you can see, i've used the url name as an ID.
I need this ID to get the correct product from my webshop.
How can I automate this? So how can I make sure that every url different then www.mystore.com redirects to www.mystore.com/shop/baseurl*dash*extension ?
Of course, I could type them all out but would take to much effort.
Thnx in advance.

RewriteEngine On
RewriteRule ^(www\.)?([a-zA-Z0-9]+).([a-zA-Z0-9]{3})(.*)$ http://www.mystore.com/shop/$2-$3/$4 [R=301,L]
This rule redirects:
http://www.foobar.com?id=1
to
http://www.mystore.com/shop/foobar-com/?id=1

Related

Rewrite within a folder

This is very basic but still eludes me, even after studying the relevant stackoverflow pages.
I want this
mysite.net/special/
to return this (the index here)
mysite.net/info/special/
showing the requested address in the browser, not the longer actual address.
The closest I’ve got (with this in the root htaccess) is
RewriteRule ^special/$ info/special/ {QUERY_STRING}
but it’s wrong.
I had thought this is a direct match-and-replace, but apparently not.
RewriteEngine is on.
Guidance appreciated. Thank you.
RewriteRule ^special/$ info/special/ [R=301,QSA,L]
RewriteRule Flags:
R=301: redirect permanently
QSA: combine query string
L: last rule
I am assuming index as index.php for your index file. we are rewriting to your existing url.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/special/$
RewriteRule ^ info/special/index.php [L]

Change subdomain link to another and keep content

I have 2 sub-domains, if the user navigate to sub-domain 1, keep the content, but change the URL to sub-domain 2. The following is not working for me, not sure about the best way of implementing this.
RewriteCond %{HTTP_HOST} ^sub1.domain.com
RewriteRule ^(.*) http://sub2.domain.com/$1 [P]
I found the solution for this issue, I hope this will reach someone needs it.
RequestHeader set Host sub1.domain.com
RewriteRule membership/new-member-application/$ http://sub2.domain.com/member/newmemberapp/ [P,L]

rewriterule for multiple 301 redirects

I've tried looking my question up, but the closest answers I've found didn't work--especially since I'm VERY new to editing .htaccess files.
I have a site that has been programmed to dynamically generate copies of a page to fit a location. For instance, example.com/help/work/ was set up to make about 100 duplicates that look like this: example.com/help/work/?city=Washington&state=DC with the city and state dynamically changing with each page.There are tons of these variations and I want to 301 redirect all the pages with a city and state parameter so they point to the original page (example.com/help/work/).
After some research, I was able to find a RewriteRule that helped me do this on a page by page basis, but only with the homepage:
RewriteCond %{QUERY_STRING} ^city=Philadelphia&state=PA$
RewriteRule ^$ http://example.com/? [R=301,L]
With all that said, I have a two part question:
Is there a way to write this so that it targets subdirectory pages? (I could only get it to do the index)
Is there a way I can use a wildcard like (.*) in a single RewriteRule so example.com/help/work/?city=Washington&state=DC and all its city/state variations point to the original page (example.com/help/work/)?
I'm a bit confused on your request. It appears you want to point every city and state to this single page. http://example.com/help/work/ See if this is what you're looking for.
RewriteCond %{QUERY_STRING} city=.+&state=.+
RewriteRule ^([^/]+)/([^/]+)/?$ http://example.com/$1/$2/? [R=301,L]
Yes, You can use a regex capture group in Rewrite rule that captures the request_uri dynmically .
Like this
RewriteCond %{QUERY_STRING} ^city=.+&state=.+$
RewriteRule ^(.*)$ http://example.com/$1? [R=301,L]

htaccess redirect of different add-on domains to folders which are associated to each domain

We tried various htaccess rewrite rules but could not get to work what we need to do. Maybe some advise here?
Assume we have a main domain (a.com) with 2 add-on domains (b.com and c.com), all pointing to the website root.
Then we have folders, all in root, like /folder_a1, /folder_a2, /folder_a3,/folder_b1,/folder_b2,/folder_b3 and /folder_c1, /folder_c2,/folder_c3 in which there are php files.
Users shall be able to come to the site via:
URL=a.com/folder_1/xxx.php and be redirected to root/folder_a1
URL=b.com/folder_1/xxx.php and be redirected to root/folder_b1
URL=c.com/folder_1/xxx.php and be redirected to root/folder_c1
Each time we want to keep in the browser address bar the URL the user came from (if he came via a.com we want to keep showing a.com... etc.)
In this example we basically have to map the url string .../folder_1, dependent on the URL used, either to folder_a1, folder_b1 or folder_c1.
We tried (amongst others):
RewriteCond %{HTTP_HOST} ^www\.a\.com [NC]
RewriteRule ^folder1(/.*|)$ /folder_a1$1 [L,NC]
RewriteCond %{HTTP_HOST} ^www\.b\.com [NC]
RewriteRule ^folder1(/.*|)$ /folder_b1$1 [L,NC]
RewriteCond %{HTTP_HOST} ^www\.c\.com [NC]
RewriteRule ^folder1(/.*|)$ /folder_c1$1 [L,NC]
But that does not do the trick. With these rules we always and up at folder_a1.
Any suggestions how we can do this?
We found the solution (thanks to the support of our host rochenhost !).
As there was no answer here (yet ;), here is what we found:
The only issue was that we did not repeat the re-write condition before every re-write-rule, which meant that the condition was only applied once, to the first rule, and to none of the following rules.
Once added, all works.
Cheers

i have a problem in .htacces (vanity url)

i am using
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://mywebsite.com/
RewriteRule (.*) http://mywebsite.com//$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1
it's working , but here my problem is i want my group with vanity url.
right now my user get vanity url like this website[dot]com/username.
But i want my group also with vanity url like website[dot]com/groupname.
can any on help in this?
That would require you to differentiate within htaccess what is a user and what is a group. I don't think that this is an option in your case since (I guess) your user and group names will be dynamic and stored in some kind of DB.
Thus, you'll have to solve the problem in PHP. You could do some rule like this:
RewriteRule ^([a-zA-Z0-9_-]+)$ userOrGroup.php?parameter=$1
and then, userOrGroup.php redirects to either profile.php or groupProfile.php (or whatever your group pages are called), depending on whether the parameter is a user name or a group name.

Resources