Currently making a php template/framework. Now I have done as advised and put all normal files in a PUBLIC folder with libraries and config in others and have placed the index.php into the public folder but then try and do a MOD_WRITE and nothing works - Im using the Coral8 Server (For testing) and have configured it all correctly to do it but doesn't seem to be working.
Here's what I've tried:
RewriteEngine on
RewriteRule ^public/?$ /public/index.php
RewriteRule ^public/([^/]+)/?$ /public/index.html
and this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>`
and this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
But none seem to work :(
Thank you in advance but someone tell me what I'm doing wrong so that I can learn from the mistake and then how to correct it.
Thank you
Is this what you're looking for?
RewriteEngine on
RewriteRule (.*)\.html$ /public/?action=$1&%{QUERY_STRING}$ [L]
RewriteRule ^$ /public [L]
So your URL will look like relution.co.uk/about.html
RewriteEngine on
RewriteRule ^$ /public/index.html [L]
//made addition on index.html and put it first so that it is the first rule to be applied and then makes the condition for the next rule to apply
RewriteRule (.*)\.html$ /public/?action=$1&%{QUERY_STRING}$ [L]
Related
I'm aware of a lot of solutions around there, and tried everything. The problem is, when I put a .htaccess in the codeigniter subfolder, it's not read. I thinks it's because of the AllowOverride directive, but I can't change that.
I tried to skip the main subfolder that is not part of wordpress, one I called "sandbox", in the root htaccess (that's part of wordpress), so it doesn't "inherit" any problem from that rewrite (for example, to not have 404 managed by wordpress in the codeigniter project).
The problem is, as I said, that the .htaccess in the /sandbox/ciproject/ folder is not read. So, I tried this in the main .htaccess, and it worked... for a little time.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?sandbox/
RewriteRule . /index.php [L]
RewriteBase /sandbox/ciproject/
RewriteCond $1 ^(application|system|private|logs)
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|img|fonts)
RewriteRule ^(.*)$ - [PT,L]
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
That allowed me to make it work for a while... but it's not working anymore. Something more I could try? I already changed the config of the codeigniter project so it doesn't use index.php, but nothing. I only get a server error 500 now, and if I delete the second half of the htaccess, I only get 404 as a response for getting rid of the index.php
I don't know if I'm losing some data, but just ask and I'll edit this, so you're not blind at this one.
Based on my understanding, your code-ignitor part doesn't work because, you have two clashing rewrite rules in your htaccess.
RewriteRule ^(.*)$ - [PT,L]
RewriteRule ^(.*)$ index.php/$1 [PT,L]
These are a clashing rule set. Remove one of the lines and then try. It should work.
Use only this code in htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sandbox/ciproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
I have a small question.
I have build a system and it is using a .htaccess to direct the traffic to the correct locations.
Now I have the following .htaccess data
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
///### (does not work.. this is a problem) RewriteRule (.*) app/template/ !page [L]
</IfModule>
The problem is actually that when I want to show a .css file located in /app/templates it also redirects to /core/
I tried to make an exception. However that does not really seem to work at my method.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
RewriteRule (.*) app/template/ !page [L]
</IfModule>
This .htaccess gives a 500 error.
Could anyone tell me what I am doing wrong? And how I can make the exception work for the template directory?
TIAD!!
You should use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) core/$1 [L]
</IfModule>
My website is v2.example.com and I am trying to write a .htaccess rule but unable.
I want this : v2.example.com/ABCDEFGH
And I want to get the value ABCDEFGH as a parameter like it is v2.example.com/index.php?id=ABCDEFGH
can anyone please help me sorting out this problem.
I tried this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*) index.php?id=$1 [L]
</IfModule>
Please help me.
Have your rule like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
</IfModule>
RewriteEngine on
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
this will crash as it goes into infinite loop, as index.php is further rewritten to index.php?id=index.php and so on
solution
RewriteEngine on
RewriteRule ^([^_]*)$ _index.php?id=$1 [L,QSA]
that is create page _index.php, and rewrite all pages not having _ to this page, this way it will not go into infinite loop, you can choose ~ instead of _ if you think you will need _ in ur parameters
I'm trying to rewrite a URL using the following rule:
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
and this is an .htaccess file I created:
RewriteEngine On
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
but when I push it to my Heroku server, I get a 500 Internal Server Error on all pages. What am I doing wrong?
Thanks
I think the main problem is you rewrite rule
try something like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]+) index.php?id=$1 [L]
</IfModule>
If you have mod_rewrite loaded, and your rules are in an htaccess file in your document root. The rules that you have are causing an infinite loop. You need to add a condition or two to prevent that:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/curation\.php
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
Or
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
I am quite new to PHP and just getting started with mod_rewrite. I know the basic lingo but come stuck when I want to simply refer to the route directory
i.e. this is not probs
RewriteRule ^settings/$ settings.php
[QSA,L]
But how to for example make:
RewriteRule ^page/(.*)$
index.php?Page=$1 [QSA,L]
which generates /page/[page-name]
Just become
/[page-name]
?
Maybe I didn't understand you but it seems that you need such .htaccess file to solve your problem.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Ignore valid files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?Page=$1 [QSA,L]
</IfModule>
This should do it:
RewriteRule ^(.*/)$ index.php?Page=$1 [QSA,L]
However, you should place that rewrite rule after all the other specific rewrite rules you have, otherwise all requests will be redirected to index.php?Page=....