First of all, I simply wanted to use another folder as the default htdocs directory.
In order to do so, I added these lines into my httpd.conf:
AliasMatch ^/php/(.+)$ F:/PHP/$1
<Directory "F:/PHP/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
The problem I experienced was that the URL rewriting I had set up for the former htdocs wasn't working properly. To do the rewriting, I had used this RewriteRule directive in my .htaccess file:
RewriteRule ^((?:(user|admin|debug)/)?[a-z_/]+)/(?:([0-9]+)/)?$ index.php?page=$1&auth=$2&id=$3
... which was located in "F:/PHP/lif-web-interface/" on my drive.
The URL I want to display is the following:
http://127.0.0.1/php/lif-web-interface/factionlist/
If it had performed correctly, I would have seen a rewritten URL with collected GET parameters on its end. When I had tried to add the [R] parameter, the output I got changed into the following:
http://127.0.0.1/F:/PHP/lif-web-interface/index.php?page=factionlist&auth=&id=
... which, surprisingly, was the thing I wanted to see. But yet, I didn't want to redirect onto that page, I just wanted to replace the URL.
Do you have suggestions what I should do?
I assume you've put those rules in the htaccess file in the F:/PHP folder. If so, then try adding a base:
RewriteBase /php/
RewriteRule ^((?:(user|admin|debug)/)?[a-z_/]+)/(?:([0-9]+)/)?$ index.php?page=$1&auth=$2&id=$3
If the rules are in the document root, then you need to include the path:
RewriteRule ^php/((?:(user|admin|debug)/)?[a-z_/]+)/(?:([0-9]+)/)?$ /php/index.php?page=$1&auth=$2&id=$3
Related
I've been trying different ways to create the url like this:
http://www.domain.com/postal-zip/123456
I've tried:
RewriteRule ^postal-zip/([0-9]+)$ code.php?thecode=$1 [L]
and
RewriteRule ^postal-zip/([0-9]+)$ postal-zip/code.php?thecode=$1 [L]
and a few more things but I have not got the result, does anyone have an idea about this?
Your rules look okay. It sounds like mod-rewrite is not turned on.
First, before your rules, make sure you have:
Options +FollowSymLinks -MultiViews
RewriteEngine On
Next, for this to work, mod_rewrite must both be installed and activated for .htaccess files. If you are not sure, to check if mod_rewrite is even installed, look at the list of installed modules in the output of phpinfo(); By default, mod_rewrite is not enabled for .htaccess files. If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
A simple .htaccess file with this:
RewriteEngine On
RewriteBase /
RewriteRule ^webshop$ /index.php?page=webshop [L]
... does not work for me because a have a file called webshop.php in the web root. Renaming the file solves the poblem, and changing the regex in the .htaccess file solves the problem, but still - it's only a partial match of the file name...? The only thing I can find on this is to use
DirectorySlash off
I've tried that and it made no difference.
Need some help here, there must be a pretty simple solution to this.
Most likely you have MultiViews options enabled. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
Disable it by placing this line on top of your .htaccess:
Options -MultiViews
I'm trying to use rewrite url rules using a .htaccess file. This seems to work fine in my main .htaccess file (only works for php pages which exist in same directory), but when I want to use another .htaccess for php file inside a subdirectory the rules don't apply at all and I get a 404 error page.
The file I want to point to is /news/story.php. story.php requests an integer variable called 'article' to fetch the article from database and display it.
So basically what I want to do is replace http://www.mydomain.com/news/story.php?article=1
with http://www.mydomain.com/news/story/article/1/
I'm using the following rules in the .htaccess file which is inside the 'news' directory.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteRule story/article/(.*)/ story.php?article=$1
RewriteRule story/article/(.*) story.php?article=$1
Thanks for your help
RewriteRule story/article/(.*)/ news/story.php?article=$1
RewriteRule story/article/(.*) news/story.php?article=$1
I know it's not original question but I've read several posts and questions here and still can't figure it out.
I'm on localhost (apache server) and default server home is in /var/www. There is a folder 'project' with several subfolders, one of them is called web with index.php file. So now if I want to go to index, I need to use full url localhost/project/web/.
I want to make it better so that if you go to localhost/project you are either redirected to localhost/project/web/ or the url remains same but it works (sorry for this naive formulation).
In .htaccess I changed directory index but then all links (since they are relative) were not working.
I tried this .htaccess in /var/www/project:
RedirectMatch permanent ^/$ ./web/
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options -Indexes
But it's not working, going to localhost/project tries to list the project directory (it is not allowed due to Options -Indexes, which is what I wanted). I need it to be independent of the 'localhost' in url because it have to work anywhere (if .htaccess is allowed)
Thanks for any advice
RedirectMatch doesn't have a base like mod_rewrite does. Even if it's in the htaccess file in the /project directory, you need the full URI:
RedirectMatch permanent ^/project/$ /project/web/
If you wanted it to go to /project/web/index.php without a browser redirect (meaning the address in the URL bar on the browser stays at localhost/project/) you need to internally rewrite the URI using mod_rewrite:
RewriteEngine On
RewriteRule ^$ web/index.php [L]
Note that mod_rewrite uses the base URI that the htaccess file is in (but the "prefix" or leading slash is removed).
Alright, I'm just trying to setup a simple rewrite rule for a site.
First off, in httpd.conf I have
LoadModule rewrite_module modules/mod_rewrite.so
Then in a seperate file I have this alias setup
Alias /vworker/ "f:/vWorker/"
<Directory "f:/vWorker/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
Alright now, so the directory of the site is
f:/vWorker/urlmask
In there I have an .htaccess file that says this
RewriteEngine on
RewriteRule ^redirect/([0-9]+)/?$ index.php?redirect=$1 [L]
Now, what I want, is if I go to the url http://localhost/vworker/urlmask/redirect/3161513 it will actually call http://localhost/vworker/urlmask/index.php?redirect?3161513
From my point of view everything seems to be set up right, and if I put gibberish in my .htaccess file I get a server error, so I know it's reading it.
What I end up with is a page that says "Not Found. The requested URL /vworker/urlmask/redirect/94173336828903446 was not found on this server."
Any ideas what I'm doing wrong?
In general, whenever you've got an Alias, you're going to need a RewriteBase to make things work as expected.
In your case, you should have
RewriteBase /vworker/urlmask/
in the same .htaccess as your rules.