So im trying to do something simple, just want to change the urls like for example:
website.com/user?slug=usernameexample to website.com/user/usernameexample and I used the code below:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?user/([^/d]+)/?$ user.php?slug=$1 [L,QSA]
Seems simple but for my surprise this is a little nightmare because in the url website.com/user/usernameexample all files like css/js and others will not work because will try to open inside the directory "user" And thats not all... Also all links and files will try to the same, so for example login.php will also try to open inside the "user" folder that does not exist...
After reading many stackoverflow answers seems that the most common answer is "Absolute Paths" or <base href="http://www.example.com/" />... However The "base href" answer don't really works properly because that brings other issues... So seems that "Absolute Paths" are the only viable answer?
I wonder If there is another solution... I did tried some small htaccess changes but they did not worked with me...
Yes, Absolute Paths are the only viable answer.
Related
I used this .htaccess file on my localhost:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
But when I uploaded my site to the ftp, it suddenly doesn't work. I set the base_url. Mod rewrite is enabled. What else can be the problem. My knowledge is very limited, I was already happy, that I programming part, but this server stuff is over my head. But I'm willing to learn it, so if you recommend a place to start, I'm open to that.
So right now only a formatted page comes in, with basic css settings and the 404 message. It's weird, that this message can be created in a form like that, so it means it's not a technical problem, but a settings problem. I googled around, tried more .htaccess files, but nothing works. Thanks for your help!
This is silly. The controllers must be named starting with a big case letter. So the only problem was, that I named my default controller as welcome.php instead of Welcome.php. It was hard to figure out, because it worked on localhost. So this had nothing to do with .htaccess at all. May be valuable to others, so they don't make the same mistake.
I have seen this error when people are using FastCGI - you need to add to the config.php:
$config['uri_protocol'] = "REQUEST_URI";
This clicks everything together - Might not be the answer to this issue but worth a try and others with your symptoms may find this useful.
Thanks,
//P
Is it still secure to have urls like:
http://www.website.eu/product.php?id_product=916
If not, what are security cons?
Can someone please point me a link on updated information about this practice regarding security.
Thank you
There's no security cons as far as I know. As long as your code sanitises all user input and you don't leak sensitive info like file paths or queries when an error occurs, you should be fine. Just be sure to block all access to directories where users should not be, such as your libraries or configuration directories.
The most basic thing that you can do here is convert this to lofical URL instead of a physical URL which it is right now.
physical URL - http://www.website.eu/product.php?id_product=916
Logical URL - http://www.website.eu/product/916
This would expose only the needed things and not the complete implementation style of the code.
To do this you will have to make some minor changes to the .htaccess file of the folder where product.php is present.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^product/$ product.php?product_id=$1 [NC]
Noob in mod_rewrite here...I'm developing a new site and using mod_rewrite.
The problem is, when I activate my rules in .htaccess, my links to CSS files and images become unreadable.
For example, I had this:
http://www.dico2rue.com/dictionnaire.php?idW=675&word=Resto-basket
That I transformed to this:
http://www.dico2rue.com/dictionnaire/675/Resto-basket
I know it's probably because the browser is looking for the CSS file in the
http://www.dico2rue.com/dictionnaire/675/css/general.css instead of the base directory, but I was hoping there was a way to to leave physical files alone, and only parse other URLs in order to avoid full paths (which apparently slows down downloas speed...?...).
thanks.
This problem doesn't have anything to do with mod_rewrite; you just need to provide a valid URL to your CSS file in the src attribute of your link tag. The relative URL you probably want to use is "/css/general.css". See the relative URL rfc.
On another note, your thinking about mod_rewrite might be a little off. In your example you are actually providing a resource in the /dictionnaire/675/ path of your server. The fact that you are using mod_rewrite to do it instead of some other method makes no difference.
you need to add these lines to check if it's not a file or directory right before the rewrite rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
I've got a really quirky issue going on with ExpressionEngine. I've got a live test site here.
Essentially, if you attempt to comment on the index's 'Question of the Day,' you get a proper redirect, but the comment never gets to the database.
If I remove my .htaccess and set the site's index page in my control panel to index.php, then all is well. But with the .htaccess and index.php removed, things go haywire.
Here are the comments of my .htaccess file:
RewriteEngine on
RewriteCond $1 ^(weblog|member|search|site|rss|search|contact|show|commentary|include|about|blog|tags|preview|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /skad/index.php?/$1 [L]
Any tips to troubleshoot this or ideas where I could be going wrong? If it's any help, you can see a screenshot of my folder structure.
Thanks so much for any answers or simply help that you can give.
More: Also, here are headers for a successful post on a blog entry and a failing post on the index.
Update: I did recently find something else strange. With identical backend settings:backend settings http://droplr.com/1sMXc9+
And identical code:identical code http://droplr.com/1sN09A+
I get http://localhost:8888/skad as one form action and http://skadaddlemedia.com/v2/v2/index.php as the other form action.
At this point, I'm completely lost as to what is going on.
the "?" after index.php in the RewriteRule suggests that you are on a server running PHP as a CGI script and thus requires the "forced query strings", correct? This may be ancillary to the problem in the question, but it can complicate things to have this requirement. Looks like you're hosted at Site5... I have no experience with them but you might try the workarounds suggested here: http://expressionengine.com/wiki/Workaround_for_Forced_Query_Strings/
Try changing [L] to [L,QSA] to see if it helps.
I'm not sure but i think that CI and EE are pretty much the same as to the way the htaccess works so this may help you out. It is by a CI guru named Ethan, can't remember the last name, but he is very active in the CI community. Anyway the way that your HTACCESS file is has really been abandoned the new way to do it is a lot easier and you don't have to state your excluded folders it is the best thing since sliced bread for users of MVC or any frameworks i just love it.
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
i can gurentee you that if it is a htaccess issue this bugger will fix it but the bext thing is you dont have to do a thing to it just drop it in and you never have to edit it again i swear by it. so freaking good like fried chicken in the summer yummy!
remember test it first by just dropping it in place of your current one you wont need all that crazy other stuff you got there in yours promise.
I got 2 sub-domains
c:\wamp\www\websiteA\ - http://websiteA/
c:\wamp\www\websiteB\ - http://websiteB/
inside websiteA got a folder for storing picture
c:\wamp\www\websiteA\photos\
in order websiteB want to access websiteA photo in websiteB's html I have to do link like
url: http://websiteB/1.html
<img src="http://websiteA/photos/1.jpg" />
the problem is I don't want to expose websiteA domain in websiteB, since two domain is inside one machine. Is it possible to achieve something like virtual host?
I also don't want to expose the physical path for websiteA, and don't want to duplicate the data.
I am thinking do something in websiteB .htaccess?
My goal is in websiteB html able to display photo with it own domain,
<img src="http://websiteB/photos/1.jpg" />
Edit: I think the question ask it this
way is better in order user request
http://websiteB/photo/1.jpg, the
backend actually request the file from
http://websiteA/photo/1.jpg, any idea do from .htaccess?
I am new in htaccess, I tried in .htaccess, but not success
RewriteEngine On
RewriteRule http://websiteA/photos/1.jpg http://websiteB/photos/1.jpg[NC,L]
Many Thanks!!!
PS: Solution need to work either windows / linux environment.
On Windows it depends on what filesystem you're using.
NTFS: http://en.wikipedia.org/wiki/NTFS_symbolic_link
FAT32 doesn't support symlinks.
Sound doggy? Can you supply reason?
What you are probably looking for is a proxy. Check it out on google
I think I got my solution, not sure is perfect or not
inside .htaccess for websiteB
RewriteEngine On
RewriteBase /websiteB/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photos/(.*)$ http://websiteA/$1 [L]
the thing I found it not so perfect is when I enter
http://websiteB/photos/1.jpg, it will redirect to http://websiteA/photos/1.jpg
but inside the HTML, I type
<img src="http://websiteB/photos/1.jpg" />
It able to load http://websiteA/photos/1.jpg without change the URL. That's look OK for me.