I'm successfully rewriting a users profile page thusly:
RewriteRule ^([a-z0-9]+)$ /profile/profile.php?u=$1 [NC]
RewriteRule ^([a-z0-9]+)/$ /profile/profile.php?u=$1 [NC]
so site.com/username was site.com/profile.php?u=username
Easy.
But now.. I'd like to have standard pages n folders like this...
site.com/login
site.com/help
etc... but the site thinks these are usernames... I've added rules to differentiate them but they dont seem to pick up - ie the one below doesnt work..
RewriteRule ^/login/twitter/$ /login/twitter/index.php [NC]
It thinks login is a username.
Any ideas?
Thanks!
You should use conditional rewrites before your RewriteRule to skip over your reserved names and files and folders that already exist on server:
RewriteCond %{REQUEST_URI} !^/reserved1
RewriteCond %{REQUEST_URI} !^/reserved2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
REQUEST_URI is the resource requested in HTTP request line. The first two lines mean that the URI should not start with your reserved names and should skip over /reserved1 and /reserved2
REQUEST_FILENAME is the same as SCRIPT_FILENAME CGI variable and contains the full local filesystem path to the file or directory matching the request.
The last two lines mean to skip real files and directolries that already exist in server.
Related
I want to redirect all url's from
domain.com/incoming-dir/ to domain.com/direct-dir/
I use the following for this:
RewriteEngine On
RewriteRule ^/?incoming-dir/(.*) direct-dir/$1 [R=301,L]
But now I want to build in an exception.
The redirect should not happen for an iPhone and iPad.
What should be added for this exception?
You should check first with %{HTTP_USER_AGENT} and exclude what you want from next rule
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !^.*(iPhone|iPad).*$ [NC]
RewriteRule ^incoming-dir/(.*) direct-dir/$1 [R=301,L]
I have a problem with website coded in Kohana framework.
I'm not author of it, but I needed to change hosting.
I moved it from other site to the new and all is ok, but when I go to some pages, wchich edit some objects on my site (admin panel -> objects (ex. hotels, tours etc.) and I choose someone object and want to edit that, then page goes from url sitename.xyz/admin,hotels,edit,<id> to sitename.xyz/404error
sitename.xyz/admin,hotels,list and sitename.xyz/admin,hotels,add works properly.
I have no idea what code can I attach. I'm adding .htacces code, but if something is needed - please notice it me, I will edit the post. My page is online, so I can give link if someone need.
.htacces code:
DirectorySlash Off
RewriteEngine On
RewriteBase /
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)public_html/index.php/(.*)$ /$1$2 [R=301,L,NE]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
I have a multilingual blog, default language is Italian and second language is English.
So I have 2 RSS feeds:
/feed
/feed/?lang=en
The first points to Italian the second to English.
I wanna both redirect to Feedburner using .htaccess, the first should point to http://feeds.feedburner.com/SimoBlog and the second to http://feeds.feedburner.com/digitalking/haPl
I successfully done it for the first with this code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
</IfModule>
I don't figure out to make it working also for the second feed URL, any help?
Thanks, Simone
You could check if the query string is equal to lang=en:
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} !=lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} =lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/digitalking/haPl [L,NC,R=302]
I would like to add some code to my .htaccess to redirect several different domains to a single domain. I have seen code that will do this for one domain such as:
RewriteCond %{HTTP_HOST} ^www\.example\.net
RewriteRule (.*) http://www.example.com/$1 [R=permanent,QSA,L]
But what is the best approach to have multiple domains redirected to a single domain?
Only redirect if the domain is not the one you want to redirect to:
RewriteCond %{HTTP_HOST} !(^www\.example\.com$)
RewriteRule (.*) http://www.example.com/$1 [R=permanent,QSA,L]
I wanted to achieve this
example.com/search_results/?action=search&username[equal]=PorscheSA
to
example.com/PorscheSA
I have used .htaccess for many websites to achieve this, but since this website is smarty based, it doesn't seem to work. Any help will be much appreciated.
Ok, this is the .htaccess file:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
In order to achieve the following I tried this:
RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1
and nothing happened.
Your question is still a little vague as to what exactly you expect to have happen, but since you've posted your .htaccess, I'll take a stab at it and see if I get what you were after.
The most obvious reason that your RewriteRule isn't working is that your test pattern doesn't match the URL you've provided as an example, as your RewriteRule requires a trailing slash (and only matches one character before that). Additionally, if you put it after the rules that you currently have in your .htaccess file, it will never match because the request will have already been rewritten to index.php.
I think that you want something like this...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]
# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
However, if the search_results/ directory doesn't exist, then this is just going to be rewritten to index.php anyway, so I'm not sure what the purpose of the redirection would be in that case. And, if it does exist, since your test pattern matches pretty much anything I'd expect to see in a site path, then everything will be rewritten to the search_results/ directory, so very little (if anything) will end up at your site root's index.php.
Based on that, I feel like maybe there's some other criteria that you may have left out, but I could be wrong.