The file structure looks like this
root
root/x
root/x/y.php
root/index.php
.htaccess code
RewriteRule (.*) /x/$1 [L]
What the htaccess file does is to remove the folder name (x) from the url so accessing y.php = http://localhost/y.php instead of http://localhost/x/y.php . This works but my problem now is the index.php shows something like this:
Index of /x
Parent Directory
y.php
I can't access the index.php. I believe the x became the root folder.
Thanks for your help!
First, you shouldn't allow index displays like this on a public server ... on your localhost it may be okay, but still, you can disable it in your .htaccess by adding this:
Options -Indexes
To address your question, you should probably add the following conditions before your rewrite rule so that the rule won't apply to any files or directories that actually exist on disk:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
This won't fix the issue you have because the .htaccess is redirecting to a non-existant /x/index.php file ... this is why it's showing the index listing for the /x directory
Related
I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.
Hi, so this may be asked elsewhere but I have searched and come up with irrelevant results.
I clearly don't know what to search for exactly.
I'm just trying to rewrite everything after a certain directory to that directories index.php.
Here is an example of the URL a visitor would SEE
website.com/search/location/United%20States
And I would like that URL to be rewritten server-side so that it loads website.com/search/location/index.php
(not a 301 redirect)
I would like the Url to stay the same but load the index.php script (to include United%20States so this can be passed to PHP to determine what the location is and if it is legitimate etc.).
Sorry I know that this will be somewhere already but I just can't find it
I have some code already but it is buggy and seems to choose when it wants to work and also sometimes uses location/index.php/United%20States which is not what I want.
Put this code in your htaccess (which has to be in your root folder)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/location/.+$ /search/location/index.php [L]
If you have Apache web server, make sure you have mod-rewrite enabled and put .htaccess file into your WEBROOT/search/location directory. Put this into .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]
This will internally redirect all requests, where file or directory does not exists, to index.php.
You could also put .htaccess file into your WEBROOT directory and write this into to:
RewriteRule ^search/location/.* /search/location/index.php
Hope this helps.
I have created a folder within WordPress public_html folder and created a test.php file in it as below.
www.mysite.com/myfolder/test.php
When I navigate to this url, I get page not found 404 error. All other files in myfolder, e.g. test.txt load without any issues. It's just php files that are not running. Could anyone please help?
My .htaccess file is
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
WordPress has its own .htaccess that is probably treating your URI as some sort of "Search Engine Friendly" thing, and translating it into some other format that WP is expecting. For example, http://www.mysite.com/myfolder/test.php might get rewritten to something like http://www.mysite.com/myfolder/index.php?target=test%25php. That would give a 404 error from within WP (not a real server 404 error). Perhaps something can be done from within WP's configuration, or you could modify the .htaccess to tell it specifically not to rewrite test.php.
This is weird since WP leaves your files alone due to RewriteCond %{REQUEST_FILENAME} !-f condition.
Try creating a myfolder/.htaccess file with this line:
# just one line here
RewriteEngine On
This will basically nullify all rewrite rules of parent folder.
Please check file-folder permission of myfolder. It should not be 777 instead it should be 755 on your server.
Please refer Wordpress php file execution
I have a directory called "public_html/hammer/" (my CMS). I want to use the image folder that is on the root "public_html/". I could simply do something like "../picture.jpg" but the content within "/hammer/" will be show on the root directory so it will then be broken when I query the html.
How can I write an ModRewrite or similar that will point "public_html/hammer/images/" to "public_html/images"?
Assuming public_html is your document root, place a rule like the following in public_html/.htaccess:
RewriteEngine On
RewriteRule ^hammer/images/(.*)$ images/$1 [L]
Basically:
RewriteEngine on
RewriteRule ^.*$ ../../$1 [L]
I've been searching the whole evening for a solution/approach for my problem with my .htaccess file.
Basically I have www.site.com with a .htaccess in the www directory with the following content:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(/admin)
RewriteRule ^[^_+/]. index.php
It works just fine and allows www.site.com/en/articles/Interesting_title/3 to be parsed by index.php which reads which controller, language and what article to display.
However I'd like for the admin system to work the same way. www.site.com/admin should have an .htaccess files that allow me to write URL's this way.
www.site.com/admin/en/articles/article_title/3 should allow me to edit article number 3 using en english UI.
Dumping $_SERVER['REQUEST_URI'] in the first case gives "en/articles/Interesting_title/3"
Dumping $_SERVER['REQUEST_URI'] in the second case gives "admin/en/articles/article_title/3"
If I at a later point choose to move administration to www.site.com/shassooo I would like to avoid changing any code other then the .htaccess files.
Cheers
Append this line in the same .htaccess file you have, not under admin sub directory:
RewriteCond %{REQUEST_URI} !^/admin/index.php$ [NC]
RewriteRule ^admin/[^_+/]. /admin/index.php [L,NC]