confused with Mod rewrite RewriteRule - apache

everything at my website is served from a master index.php at Document root
so normally all the functions looks like ./index.php?storage=seven
i wanted to make it looks better, so tried to use Mod_Rewrite as shown below
RewriteEngine On
RewriteRule ^/storage /index.php?storage=seven [L]
Now i am able to access the function using ./storage
but when somebody types ./storage/ (an extra '/' at end) or ./storage/some/junk the Link still works but the path to images/css/script in my page brakes(the paths to these is broken), which means, i just need it to be working for ./storage and everything else should give 404 error (./storage/ and ./storage//... to give 40)
Please help me out here, i am very new to Mod_reWrite
Thanks

Small change in rule ... and it started working
RewriteRule ^storage$ index.php?storage=seven [L]
By the way seven here is hard-coded from the Rule itself, please don't get confused with that
Thanks

Related

Rewrite a URL Apache

I’m attempting to rewrite a link on my Apache config file so that it looks like an internal link, but is actually external.
The link on my site will look like this, and have multiple querystrings.
http://www.mysite.com/myscript.asp?somevar=1&othervar=2
But when clicked will be rewritten as this:
http://www.othersite.com/script.asp?somevar=1&othervar=2
Here is where I am so far (not working):
RewriteRule ^myscript.asp?(.*)$ http://www.othersite.com/script.asp?(.*) [L]
Can anybody get this rule working? Thanks!
I hope this would be helpful:
RewriteRule ^myscript\.asp\?(.*)$ http://www.othersite.com/script.asp?$1 [L]
Note: question mark(?) and dot(.) have special meaning in reqular expresion, so if you want to use them as meaningless character put \ before them!

How do I rewrite www.sitename.com/thing/thing.php?otherthing=something-like-this to www.sitename.com/something-like-this?

How do I rewrite
www.sitename.com/thing/thing.php?otherthing=something-like-this
to
www.sitename.com/something-like-this?
please help me with this as I can't seem to succeed. My host uses apache 2.2. Many thanks for your help!
Update
No I don't need that trailing ? However, I used the Rewrite rule you offered me and it still ain't working. I also added a RewriteEngine On before the rules.
I have Linux hosting, .htaccess and the code is obviously semantically correct, cause otherwise I would get the all so popular 500 internal server error. I placed the .htaccess file in the folder thing and in the root of the site, but it still won't work.
There should be an option to display it in directory format instead of the PHP ? format. If not, you could use the .htaccess mod_rewrite rule to make that display in the /folder/ way.
The way I do it is that I just upload my files and each page name is index.html and then I create folders, and put each index.html in the folder. Like this:
/guidelines/
In that folder is index.html, so instead of it being /guidelines.html it's /guidelines/
Looks better without .html
You need to use mod_rewrite:
RewriteCond %{QUERY_STRING} ^otherthing=(.*)$
RewriteRule ^thing/thing.php$ /%1? [L]
No idea if you meant to have that trailing ? at the end of the rewrite, I don't think that's possible. Note that the ? at the end of the RewriteRule is to get rid of the query string, otherwise, the rewritten URL will still have the ?otherthing=something-like-this at the end.

Using .htaccess mod_rewrite to pass all URLs in a given directory to a single redirect script

Im trying to use mod_rewrite to redirect any call to /real-estate/* to rewrite.php...i know i can redirect everything to rewrite.php with this:
RewriteRule ^(.*)$ rewrite.php?url=$1 [L]
I would like to have my urls formatted like /real-estate/12345/123-anywhere-st ....where the 123-anywhere-st would be ignored, and have /real-estate/12345 sent to rewrite.php...id like the rewrite rule to only be used on /real-estate...all other areas of the site should function as is...Ive searched all over for a good tutorial or cheat sheet, but none that I can find actually explain how to format the mod_rewrite rules, they just give one or two examples and thats it...can anyone help, as well as maybe provide a link to somewhere I can learn
Thanks!
RewriteRule ^/real-estate/(.*)$ rewrite.php?url=$1 [L]

ZendFrameworks not working nice with RewriteRule

I have the following RewriteRule on my Apache with ZendFramework in the back:
RewriteRule ^/account([0-9]+) /account?i=$1 [L]
Problem that I'm having is that I have an AccountController.php for ZendFramework, so URL from browser going to ...://myserver/account works just fine. However, when I have this rewriterule in httpd.conf, and point my browser to ...://myserver/account1, then ZendFrameworks complains that /account1 controller is not found, even though I have the rewriterule in apache. My guess is that ZF is looking at the REQUEST_URI which still have /account1 in it.
Anyone knows now I can make this rewriterule work properly with ZF? What I need is basically to have URLs going to /account([0-9]+) forward to /account?i=$1 instead using my ZF's AccountController.php?
Note I do not want to 'expose' the 'i' param to users (for various reasons, and yes, they could guess at looking at account1 that it can be sequenced), hence it is an internal forward instead of an external redirect back to the browser.
Thanks!
Maybe your rule is overwritten by other Zend rules? By default, Zend takes URLs in the form controller/key1/value1/key2/value2/..., maybe you could just try this?

mod_rewrite to alias one file suffix type to another

I hope I can explain this clearly enough, but if not let me know and I'll try to clarify.
I'm currently developing a site using ColdFusion and have a mod_rewrite rule in place to make it look like the site is using PHP. Any requests for index.php get processed by index.cfm (the rule maps *.php to *.cfm).
This works great - so far, so good. The problem is that I want to return a 404 status code if index.cfm (or any ColdFusion page) is requested directly.
If I try to block access to *.cfm files using mod_rewrite it also returns a 404 for requests to *.php.
I figure I might have to change my Apache config rather than use .htaccess
You can use the S flag to skip the 404 rule, like this:
RewriteEngine on
# Do not separate these two rules so long as the first has S=1
RewriteRule (.*)\.php$ $1.cfm [S=1]
RewriteRule \.cfm$ - [R=404]
If you are also using the Alias option then you should also add the PT flag. See the mod_rewrite documentation for details.
Post the rules you already have as a starting point so people don't have to recreate it to help you.
I would suggest testing [L] on the rule that maps .php to .cfm files as the first thing to try.
You have to use two distinct groups of rewrite rules, one for .php, the other for .chm and make them mutually exclusives with RewriteCond %{REQUEST_FILENAME}. And make use of the flag [L] as suggested by jj33.
You can keep your rules in .htaccess.