I am using a WAMP Server. I need to apply rewrite rule for the pages in my local system. I have enabled the rewrite_rule from the WAMP icon at Task bar.
My Website path in local system is http://localhost/Kitty_Enfin/.
http://localhost/Test/index.php -> http://localhost/Test/home
http://localhost/Test/index.php?do=main -> http://localhost/Test/main
http://localhost/Test/index.php?do=profile&uid=1 -> http://localhost/Test/profile/1
Above are the pages I need to rewrite.
My question is: where I need to place the .htaccess file?
Whether in www/ or www/Test
What is the .htaccess Rewrite rule for the above
It will be more helpful if anyone helps on the Following issue.
Thank you for your reply. When I used the above it not worked for me. But I used another rewrite rule which works for the first two:
RewriteRule ^([^/\.]+)/?$ /\Test/\index\.php [L] - Working
(http://localhost/Test, http://localhost/Test/index)
RewriteRule ^([^/\.]+)/?$ /\Test/\index.php?do=$1 [L] - Working
(http://localhost/Test/main)
RewriteRule ^profile/([^/\.]+)?$ /\Test/\index.php?do=profile&uid=$1 - Working but the CSS and other scripts are not work here.
And also the links in the pages are http://localhost/Test/profile/ instead of http://localhost/Test/.
Do you have any idea on this issue? Please correct me if I did anything wrong.
Do you have any idea on this issue. Please correct me any thing i did wrong
Thanks
RewriteRule ^/?index.php home/
RewriteRule ^/?index.php?do=(\w*) $1/
RewriteRule ^/?index.php?do=(\w*)&uid=(\w*) $1/$2
place the .htaccess in "Test" folder
I can only answer this from your clue
Related
having issues with what i think is linked to the mod rewrite in mamp.
The rewrite works fine on the live server, but im working locally with MAMP and getting issues.
The problem is linked to this:
I rewrite the following URL:
http://localhost/BuildSanctuary-Dev/viewbuild/64/three-fiddy-z/1
That should rewrite as:
http://localhost/BuildSanctuary-Dev/viewbuild.php?id=64&title=three-fiddy-z&page=1
The issue is that i get a 404 for page not found.
The requested URL /viewbuild.php was not found on this server.
Which it clearly is... but if i visit just /viewbuild.php it works fine.
The rewrite in the .htaccess is:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
Any ideas? I have done the research and everything in the apache conf is showing as Allowing All...
Thanks.
Your rewriterule redirects to /viewbuild.php and not /BuildSanctuary-Dev/viewbuild.php:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /BuildSanctuary-Dev/viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
A mabye better variant would be to put the .htaccess into the /BuildSanctuary-Dev/ folder and use a relative path as redirect:
RewriteBase /BuildSanctuary-Dev
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
I'm having some issues figuring out how to use an htaccess file. I've got apache/php installed on an ubuntu system and mod_rewrite is turned on (php_info() states that it's in the list of loaded modules). The web server works, displays html and php files, so I'm happy with that.
What I'm trying to figure out now is how to use an htaccess file properly. I created a directory, /data, with an index.php file in it. All I want it to do at the moment is just display the $_REQUEST variable so I can see if things are working the way I assume they should.
Example: If I type in the following URL: localhost/data/info1/ I want the htaccess file to access localhost/data/index.php?request=info1
However, no matter what I enter in to the htaccess file, I keep getting 404 errors, and I'd like to understand why.
Here's my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule data/(.*)$ data/index.php?request=$1 [L]
</IfModule>
I've made no changes to the config file, to activate mod_rewrite, I used the ubuntu a2enmod command so ubuntu did it for me. After that, I restarted apache.
What I can't figure out is why this doesn't work. My assumption is that there's still some sort of configuration I need to do on the server end, but I honestly don't know what. Is there any advice anyone can offer me?
Here's the fix:
RewriteRule ^data/(.*)$ data/index.php?request=$1 [L]
(You were missing a ^)
EDIT:
In the OP, you have another leading / in the URL example, in this case it'd be:
RewriteRule ^data/(.*)/$ data/index.php?request=$1 [L]
My URL rewrite works perfectly on my testing server, but not on the live server.
I contacted the support team and they told me that mod_rewrite is already enabled on my hosting plan.
Here is my .htaccess file
RewriteEngine On
RewriteRule ^index.html$ index.php [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ work-tag.php?d=$1&t=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ work-tag.php?d=$1&t=$2
RewriteRule ^([a-zA-Z0-9_-]+)$ work.php?d=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ work.php?d=$1
Anything wrong?
Thanks
I got the same problem, but if you was asked about turned mode_rewrite - check it. I was told the same but I didn't find my htaccess working so I checked it by myself. And I found that mod_rewrite was still off.
phpinfo();
and have a look at the "Loaded Modules". If you see it so the server is not a problem. And need to go futher.
I finally fixed it by adding the following line as a friend suggested.
RewriteBase /
Thanks for your follow-up guys :)
Alright, so I've downloaded a CMS for a server I'm setting up and I have some difficulty with the path the files are on.
I have put the CMS in a subdirectory on my server as the root directory is already being used by another CMS. However, the CMS repeatedly uses "/" in the code to link to their files. For example, an image is found using this code:
<img src="/images/banner.png" />
As you know this will not work, because the link above redirects the request to the images folder in the root of the server, not the subdirectory. The CMS also came with a ".htaccess" file, so I immediately thought that I could redirect all requests made using the "/" character to the subdirectory on the server. This is the original ".htaccess" file:
RewriteEngine On
RewriteRule ^index.php(|/)$ content/.php
RewriteRule ^error.php(|/)$ content/error.php
RewriteRule ^housekeeping(|/)$ housekeeping/index.php
RewriteRule ^(|/)$ content/$1.php
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ content/$1.php
RewriteRule ^rd/([^/]+)(|/)$ /rd.php?id=$1
RewriteRule ^quickregister/start(|/)$ /register/start.php
RewriteRule ^quickregister/step2(|/)$ /register/step2.php
RewriteRule ^quickregister/step3(|/)$ /register/complete.php
RewriteRule ^community/online(|/)$ content/online.php
RewriteRule ^community/vip(|/)$ content/vip.php
RewriteRule ^credits/goldvip(|/)$ content/goldvip.php
RewriteRule ^home/(..*)$ content/home.php?u=$1
RewriteRule ^articles/(..*)$ content/articles.php?story=$1
ErrorDocument 403 /content/error.php
ErrorDocument 404 /content/error.php
I thought that by adding
RewriteRule ^/$ /subdirectory/
the requests to "/" would be redirected, but to no avail. I have checked the apache configuration and it seems that overwriting the config using htaccess files is enabled, so if anyone is able to help me out I'd be very happy.
Thanks in advance!
EDIT:
I came real close to a solution. I inserted this code just below "RewriteEngine on":
RewriteRule ^(.*)/(.*)$ /private_servers/strebbohotel/$2
This returned the following error page when visiting the url "http://mysite.com/private_servers/strebbohotel/content/.php":
Not Found
The requested URL /private_servers/strebbohotel/.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
As you can see, it skips the "content" subdirectory for some reason. I believe it has something to do with the other lines of the .htaccess file but I can't figure out which ones. It also could be that I need a more complex regex, but I'm not particularly good with it so if someone could help me further I'd be thankful.
You have to change the .htaccess file on yout root directory - and that will mess with the other CMS. The only solution that comes to my mind is to use combination of RewriteCond's:
RewriteCond %{HTTP_REFERER} my_better_cms_url_regex
RewriteCond %{REQUEST_URI} ^/images/.*$
RewriteRule ^.*$ /subdirectory/%{REQUEST_URI}
That should do the trick. If you want to customize it, refer to this cheatsheet (or simmilar). But be aware, that .htaccess in root directory is checked against ALL requests made to your subdir cms - therefore the need for second condition.
The .htaccess file in your CMS subdirectory would have no effect on requests made against the server root directory. You would need to add an .htaccess there.
Even then though, I don't know how you would differentiate requests from the CMS (like the image request in your example) from those intended for the application in the web root.
Does your CMS not have any configuration setting that allow you to specify a path the the files other than the web root?
You want to use:
RewriteBase /another_root_dir/
in the beginning of your .htaccess file
I have enabled mod_rewrite in my Xampp Apache. When I run my phpinfo() page, I saw mod_rewrite under Loaded Modules. So I think it's enabled.
Then I create a folder clean-url under htdocs. Inside clean-url folder I have 3 files
1) index.php here I put
Welcome
2) Test. php
3) .htaccess
Here I put
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
I want to run the index page, and by clicking on that hyper link I want to display the test.php page with URL
mydomain/clean-url/test
I know I am in a wrong path. What am I doing wrong? Also I don't know any idea about URL rewriting and .htaccess.
There is a dash in clean-url, but your regex does not recognize it.
Change your .htaccess to
RewriteEngine On
RewriteRule ^([a-z-]+)/([a-z-]+)$ /$1/$2.php [L]
and place it in htdocs/ instead of htdocs/clean-url/.
i think you shouldn't use /$1/$2.php, just simply /$2.php
because you ask the rewrite to access the folder clean-url and open test.php in that folder.
try
^(.*)/(.*)$ /$1.php [L]
and see how it works ... then you should format in more complex regex.