htaccess mask for my url - .htaccess

I'm trying to mask a part of my url using .htaccess but I'm having several issues
my url is
http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/
I'd like to remove the duplicate ristorantitalianetwork.com, so I'd like that my url will be like
http://ristorantitalianetwork.com/admin/
I've used
RewriteRule ^ristorantitalianetwork.com/([^/]*)$ ?q=$1 [L]
but it doesn't work
Could you please help me to figure out how to solve this problem?
Thanks a lot
Best regards

You really need
RewriteRule ^/admin$ /ristorantitalianetwork.com/admin [L]
Bear in mind that the URL you should expose to users is http://ristorantitalianetwork.com/admin/ which will then internally get converted (rewritten) to http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/.
It is not the other way round as many believe.

You almost did it! But...
In your question, your rewriterule says that it is applied on URLs that don't end with a slash (/). And you say you want to rewrite some URLs... and give URLs examples with a slash (/).
If you need to do a real redirect (i.e. the URL in the browser changes):, here's the good rewriterule:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,R=301,L]
If you need to do only internal redirect:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,L]
Keep in mind that the URL must end with a slash (/).

Related

htaccess RewriteRule not processing if not all parameters are passed

Hoping someone can help me with this issue...
I have a RewriteRule set up in my htaccess file that looks like this
RewriteRule ^/?find/(.+)/?in/(.+)/(.+)/ /page.html?&type=$1&city=$2&state_abbrev=$3 [L,QSA]
The rewrite works fine if I have a URL that contains all the parameters specified for example: http://www.site.com/find/doctors/in/dallas/tx/
The issue is, I would like to have this rewrite work even if one of the parameters is missing. For example, if I only entered http://www.site.com/find/doctors/ I would still want it to redirect to 'page.html' and just not have the parameters completed. So in that case it would be writing to http://www.site.com/page.html?type=doctors&city=&state_abbrev=. Currently, if I type in a URL that doesn't have all parameters in it the RewriteRule will not work. Any ideas how to fix this issue?
Thanks in advance...
Replace your rule with this:
RewriteRule ^/?find/([^/]+)(?:/in/?([^/]*)/?([^/]*)/?)? /page.html?type=$1&city=$2&state_abbrev=$3 [L,QSA]
There is nothing stopping you from having multiple rewrites. I have many in my .htaccess for different things and many times you have to. Not one rewrite will work for all occasions.
You could try this.
RewriteEngine on
RewriteRule ^find/(.*)/in/(.*)/(.*) page.html?type=$1&city=$2&state_abbrev=$3&%{QUERY_STRING} [L]
RewriteRule ^find/(.*) page.html?type=$1&%{QUERY_STRING} [L]
It will first look for the full URL
http://www.site.com/find/doctors/in/dallas/tx
Then forward it to the first Rewrite rule.
But then if you used this
http://www.site.com/find/doctors
It will skip the first rule and it will match the 2nd rule redirecting to just the partial query string.
Hope that helps but you can make as many rules or conditions you want. And the order in which they come does matter.

Using mod_rewrite to mask a directory/file name in a URL

I've taken my site down for some prolonged maintenance and am using mod_rewrite to send all requests to a single page: www.mysite.com/temp/503.php
This is my .htaccess file which works fine.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/temp/503.php [NC]
RewriteRule .* /temp/503.php [R,L]
However, what I'd also like to be able to do is to hide /temp/503.php in the resulting URL from the visitor.
I know this is perhaps trivial and I'm sure fairly simple to achieve, but with my limited mod_rewrite skills I can't seem to get it to work.
Any help would be much appreciated.
Thanks.
Just get rid of the R flag in the rewrite rule, which tells the rule to redirect the request, thus changing the URL in the browser's location bar. So the rule would look like:
RewriteRule .* /temp/503.php [L]
which internally rewrites the requested URI instead of externally telling the browser that it's been moved to a new URL.

Why doesn't this URL rewrite work?

This is a page on my domain: www.mydomain.com/en/stats.php
I want it to look like this: www.mydomain.com/en/statistics/players
This is pretty simple to accomplish, but for some reason the htaccess code below doesn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/statistics/players stats.php [R=301,L,QSA]
I get a 404 error when I try to open the SEO-friendly version. The page opens fine when I use the regular URL. What am I doing wrong?
The URL might not have a leading slash. Try without or optional slash. Additionally, you must check for the leading en, when you anchor your pattern at the beginning
RewriteRule ^/?en/statistics/players /en/stats.php
What worked in the end is the following:
RewriteRule en/statistics/players en/stats.php [NC,L]
I think it needs to be:
RewriteEngine On
RewriteRule ^en/statistics/players en/stats.php [QSA]
The R=301 means it will perform a redirect instead of a rewrite and try to redirect to /stats.php which doesnt exists I guess.
The L flag means that this is the last rewrite rule that will be processed for this request, which in this case I doubt is what you want. If there are rewrite rules further down for /en/stats.php they wont be processed.

httacces Rewrite URLs

I wanted to rewrite some urls from
www.example.ro/women_shoes.php to www.example.ro/women-shoes/
and with pagination looks like
www.example.ro/women_shoes.php?page=1 to www.example.ro/women_shoes/pagina-2/
www.example.ro/men_shoes.php to www.example.ro/men-shoes/
with pagination like the first one
www.example.ro/sandale_barbati.php to www.example.ro/sandale-barbati/
and so on..
for the last example i tryed
RewriteRule ^sandale-barbati/pagina-([0-9]+)/ /sandale-barbati.php?page=$1 [L]
RewriteRule ^sandale-barbati/?$ /sandale_barbati.php?$
but i need to write that for every page...
is there a way to do that automaticaly for all pages ?
thanks
If you always use the same naming for all your pages, this will work:
RewriteRule ^([a-zA-Z]+)([-_]){1}([a-zA-Z]+)/pagina-([0-9]+)/$ $1_$3.php?page=$4
RewriteRule ^([a-zA-Z]+)([-_]){1}([a-zA-Z]+)/$ $1_$3.php
RewriteRule ^([a-zA-Z_]+)/pagina-([0-9]+)/$ /$1.php?page=$2
RewriteRule ^([a-zA-Z_]+)/$ /$1.php
You can surf to /women_shoes/ and it will be the /women_shoes.php page.
You can surf to /women-shoes/ and it will be the /women_shoes.php page.
You can surf to the /shoes/ and it will be the /shoes.php page.
I hope this has met all your requirements and was of sufficient help to you. For future reference, the website http://www.regular-expressions.info/ is very handy when dealing with RegEx (such as .htaccess rewrite rules).

get the index.php with .htaccess

I'm using a bunch of ReWrite rules in my .htaccess such as these
RewriteRule ^brochure/([^/]+)/?$ brochure.php?cat_path=$1
It's all working great thanks to answers I found by searching this site. But I've got a tiny little snag.
This rule works perfecty at the moment
RewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php It catches all my urls like www.mysite.com/shane and requestes shane.php - So far so good, but when I call www.mysite.com I need it to request index.php
Which rule could I use for this?
Thanks people.
UPDATE - For the sake of future users needing similar help.
My rule of ^([a-zA-Z0-9_-]+)?$ $1.php was causing the problem I mentioned above. The question mark ? is not needed in this type of rule, when you remove the question mark the index.php file in the directory returns to being the default landing page. Thanks to Tomalak for the Help.
You don't need any rule for it. Just make sure that .php default index files for the directory and it'll happen automatically.
Update
I think that your rule
^([a-zA-Z0-9_-]+)?$ $1.php
should in fact be
^([a-zA-Z0-9_-]+)$ $1.php
so that it does not conflict with requests where the filename isn't given (which you want to direct to index.php).
I think this is what you're looking for,not sure thought:
RewriteRule ^/$ index.php
You can either do as Tomalak says, and ensure the DirectoryIndex is set to load index.php.
Or close to what James says,
RewriteRule ^/?$ index.php [L]

Resources