i have a problem in .htacces (vanity url) - .htaccess

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.

Related

Redirect index.php with parameters to a folder and remove parameters using htaccess

I have searched but cannot find a specific answer for this exact redirect style...
I have this structure of URL with this specific parameter:
https://websitename.com/directory/index.php?option=com_virtuemart&view=cart
I want it redirected to:
https://websitename.com/shopping-cart/
Note that the above mentioned "directory" changes, but the index.php with the parameters stay the same. No matter what the directory is, I always want it to go to the same exact redirect.
I cannot seem to get the right redirect working in htaccess. Can anyone help?
You can use this redirect rule as your first rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?option=com_virtuemart&view=cart [NC]
RewriteRule ^ /shopping-cart/? [L,R=308]
# remaining rules go below this
You can use a set like this. It takes care on the param view=cart
RewriteCond %{QUERY_STRING} (^|&)view=cart
RewriteRule ^(.*)$ /shopping-cart/? [L,NC,R=301]
If you want to keep the querystring params, then change
/shopping-cart/?
to
/shopping-cart/
without questionmark

rewrite url and get variable

How can I get the second part of a url to be a variable, rewrite it, and provide a fancy URL.
So example www.mywebsite.com/AFL would rewrite to www.mywebsite.com/index.php?league=AFL but would still display as www.mywebsite.com/AFL.
I am using the same pages for multiple leagues. When a user signs up they establish a league name in the database and then on each page I look for the league variable to display the info.
I also have many different pages. So a user could go to www.mywebsite/AFL/schedule_teamdisplay.php?Team=ABC&Year=2014. This would rewrite to www.mywebsite.com/schedule_teamdisplay.php?league=ALF&Team=ABC&Year=2014.
The league will always be the second entry in the URL.
Thanks
You can put this code in your htaccess (which has to be in your root folder)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?league=$1 [L]
RewriteCond %{DOCUMENT_ROOT}/$2 -f
RewriteRule ^([^/]+)/([^/]+)$ /$2?league=$1 [L,QSA]

How can I link a subdomain to a joomla user?

We've got a custom component that does all sorts of wonderful things for a a registered user. Among the requirements is the ability to use the username as a subdomain to retrieve and use a variety of their settings. e.g. http://abc.ourdomain.com must retrieve the jos_users record with the username "abc". From there we use that info in the session and carry on with component functions with those values.
I've tried tinkering with $_SERVER["HTTP_HOST"] to get things started, but am hoping that there is a cleaner approach with htaccess, or a plugin that would serve the purpose better.
Something like this might work in one .htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www\. [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.ourdomain\.com [NC]
RewriteCond %{REQUEST_URI} !getuser\.php [NC]
RewriteRule .* http://ourdomain.com/getuser.php?user=%1 [L]
Maps silently
http://abc.ourdomain.com
To:
http://ourdomain.com/getuser.php?user=abc
Captures the subdomain abc into group %1 and appends it as query to the script.
abcis a variable string.
getuser.php can be any script. The key user is an example, it can be any name too.
For permanent redirection, replace [L] with [R=301,L]

.htaccess redirecting domain alias'

I have a client that has a good amount of domain alias' and wants them all redirected to the one main domain on the site. They also want to know which of the domain alias' is doing the redirecting. I have that part down but I want to optimize the code to the best most proper way it should be and to eliminate the amount of code I have to write. I am wanting to know if there is a way to pass to the RewriteRule url the domain alias that was used.
This is what I have now. I am looking for the domain alias that is being hit and then passing that alias to the url. Then in google analytics I can see how many times that url was used to hit the page.
RewriteCond %{HTTP_HOST} ^(www\.)?domain-alias1\.com [NC]
RewriteRule ^(.*) http://www.main-domain.com/?domain-alias1\.com$1 [R=301,L}
But my goal is to not have to write both the condition and rule for every single domain alias.
Is there a way to see which alias was hit and then have the rewrite rule automatically add that to the position I have specified?
I had originally tried something like this just to see if it would work(although I have tried many different ways):
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z]+)\.com [NC]
RewriteRule ^(.*) http://www.main-domain.com/?$1\.com$2 [R=301,L]
You can try something along these lines:
RewriteCond %{HTTP_HOST} !^(www\.)?main-domain\.com$ [NC]
RewriteRule ^(.*) http://www.main-domain.com/$1?domain=%{HTTP_HOST} [R=301,L]
With this any request NOT for domain www.main-domain.com will be redirected to www.main-domain.com with the domain name in query string domain.

PHP and htaccess redirection: Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

let's say I want to use .htaccess to rewrite the following.
Rewriting /user.php?username=xyz to /xyz.
I would use:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
The problem is once this is done, how do I access the username in my other links?
so /mike/details.php
How do I get the value of username ('mike') to automatically be added to the URL so it's like:
/username/details.php?username=mike
What would I need to change in .htaccess to get this value? Or do I have to do it in the PHP script to parse the URL?
Thanks
try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ user.php?username=$1 [L,QSA]
I think passing the username as a query string parameter is not a good solution.
So, make the user data to be stored in the session (server side) and let the session mechanism retrieve it by means of session ID (passed through cookies or GET, it doesn't matter)
Your rewrite rule can still redirect to user.php setting the username parameter, but then user.php will store the user name and its data in the session ... from now every other php script that access the $_SESSION container (invoking session_start()) can easily retrieve every user related data it needs
My 2 cents :)
This will overlap with other rules in the site with starts with anytext
like say ^abc

Resources