taith Posted May 1, 2009 Share Posted May 1, 2009 (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 http://url.com/var/var2 <-- works 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 More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 Wrong forum! You're passing a variable to a HTML file? May I ask what $_GET['s'] supposed to be in the 3 cases you presented above? I don't really get it from your RegExp. So if you clarify, I may be able to help. Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823852 Share on other sites More sharing options...
taith Posted May 1, 2009 Author Share Posted May 1, 2009 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 More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 RewriteEngine on RewriteRule ^images/.*$ - [PT] RewriteRule ^jscripts/.*$ - [PT] RewriteRule ^http://(www\.)?(.*?)\.com/(.*) index.php?s=$3 [R=301,NC,L] What about that? Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823876 Share on other sites More sharing options...
taith Posted May 2, 2009 Author Share Posted May 2, 2009 viable try... but nope... that just blocks everything... hmmm on that path... i also tried RewriteRule ^http(s?)://(.*)/(.*) index.php?s=$3 [NC,L] still no joy Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823885 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Oh oops, I copied that from one of my files. Forgot to remove the last bits. Try this: RewriteRule ^http://(www\.)?(.*?)\.com/(.*) index.php?s=$3 [L] Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823887 Share on other sites More sharing options...
taith Posted May 2, 2009 Author Share Posted May 2, 2009 still no joy RewriteRule ^http(s?)://(www\.)?(.*)/(.*) index.php?s=$3 [NC,L] and still getting 404 errors... Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823896 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 RewriteRule ^(.*) index.php?s=$1 ? Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823901 Share on other sites More sharing options...
taith Posted May 2, 2009 Author Share Posted May 2, 2009 http://url.com/var --> $_GET['s']=index.php :'( Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823907 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 You have: Options +FollowSymlinks right? Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823909 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 2, 2009 Share Posted May 2, 2009 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 More sharing options...
taith Posted May 2, 2009 Author Share Posted May 2, 2009 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? Link to comment https://forums.phpfreaks.com/topic/156461-solved-modrewrite/#findComment-823919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.