http://localhost/clean_urls/user/whtffgh redirect fine to this http://localhost/clean_urls/user/whtffgh/ (pretty much anything I put there works).
http://localhost/clean_urls/user/cohen however, redirects to this
http://localhost/clean/ and I have no idea why. It should just add a /
Heres my .htaccess code
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /clean_urls/user/$1/ [L,R=301]
RewriteBase /clean_urls/user/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?user=$1
</ifModule>
UPDATE:
The code works besides when I put cohen as the username. The second part of the .htaccess file is making user/index.php?user=username look like user/username so its just a $_GET variable that looks nice in the url and is SEO friendly (apparently).
I am just learning this stuff and making a webapp to try it out so not really sure where its going but I do think I will need another variable on the end. http:://localhost/clean_urls/user/fred/someverb
You misunderstand what the RewriteBase directive is used for. It helps the rewrite engine in a "per directory" context to convert the relative URIs to the correct filename equivalent.
You should only have one RewriteBase directive per .htaccess file. The rewrite engine by default will use the lowest .htaccess file on the path with the RewriteEngine On directive set.
So in DOCroot (that is the directory where a "GET /xxx" is mapped to, this should be
RewriteBase /
If your .htaccess file is in DOCroot/clean_urls/user then it should have
RewriteBase /clean_urls/user/
How do you want to decode URIs of the form http:://localhost/fred or are you only wanting do process URIs of the form http:://localhost/clean_urls/user/fred/. What about http:://localhost/clean_urls/user/fred/someverb?
Let me know and where you are putting you .htaccess then I can give you the right content.
Related
The website I'm working on is using some cms. I need to add a static website to this. When I put mypage.html in the main directory and go to www.website.com/mypage.html it works. I would like the page to be accessible without '.html' ending. I experimented with editing htaccess files but always end up with error of too many redirections.
What I entered were various combinations, for example
Redirect 301 http://website.com/mypage http://website.com/mypage.html
The htaccess file I'm using looks like this:
:Location /*.php
Use php54
:Location
RewriteEngine On
DirectoryIndex index_prod.php
Options -Indexes
RewriteRule ^.*\.(css|png|swf|js|gif|jpeg|jpg|flv|pdf|doc)$ - [L]
RewriteRule ^net2ftp - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^/?$ plug.html [L]
#RewriteCond %{REQUEST_URI} !=/
RewriteRule ^/?.* index_prod.php
I'm looking for tips or to be explicitly told what and where to put in htaccess file to make it work (if it's possible)
Could you please try following, considering that you want without extension file URLs to be served by html extension files. Also since you didn't mention any specific condition before RewriteRule hence that redirection errors are coming to it, because its keep on redirecting in lack of any condition/check's presence(till its maximum redirection limit is crossed).
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [NC,L]
I have to create a page handler, which should read the URL, and do specific operations based on querystring.
I'd need to use .htaccess to do some URL rewriting thing to point everything at a certain file which does the processing, in such a fashion:
https://example.com/folder/page1/
https://example.com/folder/page2/
And the processing file is https://example.com/folder/index.php
Is there any way to do that (possibly by removing the index.php part)?
try this out and see if this helps you achieve what you are looking for.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
The above code is taken for reference from WordPress and it should work when the "RewriteBase /folder/" folder name is updated with your folder and .htaccess file has to be placed in the root/folder directory where your index.php file is located.
I know this question has been asked and answered many times, but my experience of .htaccess, regualr expressions, mod rewrites etc.. have normally drove me crazy.
I see on most websites the structure of the url is in a directory-like structure, wwww.linku.biz/edit. My ultimate question is how do you do this?
Are all these sites behind the scenes have normal URL variables but just re-wrote? such as www.linku.biz/myprofile?edit="whatever" , is this all done with .htaccess, and mod_rewrites?
I want to type in my url www.linku.biz/search however its actually www.linku.biz/search.php
I want to type in my url www.linku.biz/JackTrow however its actually www.linku.biz/profile.php?us="JackTrow
Also I want data re-wrote when I have lots of URL data, such as www.linku.biz/search?a=1&b=2&c=3 actually beeing www.linku.biz/search.php?a=1&b=2&c=3
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search\.php\[?^\s] [NC]
RewriteRule ^ search? [R=301,L]
RewriteRule ^search/?$ search.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ profile.php?us=$1 [QSA,L]
Please note that your requirement 1 & 3 will both be covered by rule # 1
Add this rules to your .htaccess file in Root folder :
To do this www.linku.biz/JackTrow <--- www.linku.biz/profile.php?us="JackTrow
RewriteRule ^profile.php?us=(.*)$ /$1 [R=301,L]
To do this : www.linku.biz/search however <--- www.linku.biz/search.php
RewriteRule ^(.*).php$ /$1 [R=301,L]
Your last one , i have not understood what you want exactly.
I'm having an issue with mod_rewrite where I want to match—and replace—a specific URL. The URL I want to rewrite is:
http://example.com/rss to http://example.com/rss.php
That means, if some one were to append anything after rss a 404 Not Found response be sent. Currently I'm using this mod_rewrite snippet:
Options -Indexes
RewriteEngine on
RewriteBase /
# pick up request for RSS feed
RewriteRule ^rss/?$ rss.php [L,NC]
# pass any other request through CMS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) index.php/$1
But this matches rss and rss with anything else added to the end. How can I re-write the above to acces only http://example.com/rss as the pattern for mod_rewrite to match against?
You are getting this error because /rss is being redirected twice in your rules by both RewriteRules. Have your rules like this:
Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
# pick up request for RSS feed
RewriteRule ^rss/?$ /rss.php [L,NC]
# pass any other request through CMS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^rss\.php$)^(.*)$ /index.php/$1 [L,NC]
So with above rules it will redirect /rss OR rss/ URIs to /rss.php however /rss/foo will be redirected to /index.php since your 2nd rule is forwarding everything to /index.php
I was suprised to see that your rules just don't work, because in my first attempt I would have come to a very similar solution. But looking at the rewrite log revealed the real issue.
As discribed here the server prefers real files over directories. So internally rss/something becomes rss.php/something when applying the rewrite rules and things get weird.
So, one solution is to check if the Option MultiViews is enabled for the web directory either in .htaccess or in the vhost configuration. If so, remove it - which is what worked for me in this example.
If you need MultiViews, then I guess the only chance is to rename rss.php to rss-content.php and change the rule accordingly.
One additional note: you might want to add the following line after the # ... CMS block to prevent endless recursive calls.
RewriteRule ^index\.php/.* - [PT,L]
I hope this solves your rewrite problem.
I want to make
http://domain.com/index.php?query=query
look like
http://domain.com/query
I know I need to use .htaccess, but I have no idea how to approach this.
Something like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteBase /
RewriteRule ^(.+) /index.php?query=$1
Edited:
If you really want your URLs to look like you asked, you should host all your media files (CSS, JS and images) in another virtual host, lets say, http://media.domain.com - because can't tell the difference if "query" matches the name of an existing file on domain.com.
The keyword to search for is RewriteRule.
The Drupal .htaccess file is a good example of mapping /?q=query to /query, but not redirecting things which provide an explicit match - so /files/something.css which is a real file will not be redirected. Here's the relevant snippet from Drupal's .htaccess with ?q= changed to ?query=.
RewriteEngine On
RewriteBase /
# Rewrite URLs of the form 'index.php?query=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]