Jump to content

[SOLVED] modrewrite


taith

Recommended Posts

(i hate regex)

 

question...

 

i have the following modrewrites

RewriteEngine on
RewriteRule ^images/.*$ - [PT]
RewriteRule ^jscripts/.*$ - [PT]
RewriteRule ^(.*/.*)$ index.html?s=$1 [L]

 

which works swell... except! when you dont put the trailing / after the first segment

 

aka

 

http://url.com/var <-- treats it like a file/folder... aka file not found

http://url.com/var/ <-- works :D

http://url.com/var/var2 <-- works :D

 

i'm certain the problem is with ^(.*/.*)$... but only having 1 .* fails horribly (doesnt pass any info via the $_GET['s'])...

 

does anyone have anyone know how i can fix this?

Link to comment
https://forums.phpfreaks.com/topic/156461-solved-modrewrite/
Share on other sites

basically... asis... it takes the url and turns

 

http://url.com/var/var2/ --> http://url.com/index.php?s=var/var2/

http://url.com/var/var2 --> http://url.com/index.php?s=var/var2

http://url.com/var/ --> http://url.com/index.php?s=var/

http://url.com/var --> 404 page not found

 

consider the .html a .php file(updated for simplicity)... i had that set elsewhere, to parse .html files as a .php file

Link to comment
https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823872
Share on other sites

I think you are looking for that :

 

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?s=$1 [L]
</IfModule>

 

RewriteCond %{REQUEST_FILENAME} !-f mean only if the file didn't exist. It won't redirect your .js and .css and any file that exist. Everything else will be sent to index.php.

 

<?php
echo $_GET['s'];
?>

Link to comment
https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823914
Share on other sites

I think you are looking for that :

 

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?s=$1 [L]
</IfModule>

 

RewriteCond %{REQUEST_FILENAME} !-f mean only if the file didn't exist. It won't redirect your .js and .css and any file that exist. Everything else will be sent to index.php.

 

<?php
echo $_GET['s'];
?>

 

perfection! tytytytytytyty

 

i mention how much i dont like regex? :D

Link to comment
https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823919
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.