Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

htaccess rewrite?

Dont know where to put this other than here. If its in the wrong section please just tell me.

So I am trying to rewrite www.mysite.com/view.php?code=ANY_LETTER_OR_NUMBER

to www.mysite.com/view/ANY_LETTER_OR_NUMBER

This rewrties my .php to just /view/

PHP Code

<?php 
RewriteCond 
%{SCRIPT_FILENAME} !-d
RewriteCond 
%{SCRIPT_FILENAME} !-f
RewriteRule 
^(.*)$ $1.php 

How can I do this?


This is what I have currently:

RewriteRule ^view/(.+)$ /view.php?code=$1 [L,QSA]

Doesnt work
http://stackoverflow.com/questions/12138...ual-folder

This should help you somewhat, i never made it look like a directory before. For a shortener i worked on i used this:
RewriteRule ^(\w+)$ filename.php?id=$1

It just left with the id/num but without the directory.
(Jan 27, 2017 10:45 PM)Yani Wrote:  Is this your whole file? Maybe you have something above that rule that fires first?

Yeah its my whole file. Want it to take a directory under view.
(Jan 28, 2017 04:14 AM)Yani Wrote:  You have to add this above the ruleset:

Code
RewriteEngine On

I have that on already. Still doesn't work.
Any ideas??
(Jan 28, 2017 04:45 AM)Yani Wrote:  Maybe look at your apache access log?

Should this work then?

Code
RewriteRule ^view/(.+)$ /view.php?code=$1 [L,QSA]
Try this

Code
RewriteEngine On
RewriteRule ^view/([^/]*)\.php$ /view.php?code=$1 [L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
(Jan 29, 2017 04:49 PM)NoSuchAgency Wrote:  Try this

Code
RewriteEngine On
RewriteRule ^view/([^/]*)\.php$ /view.php?code=$1 [L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

It works but all of my code is gone weird.

https://hisky.space/view/car

Look at that URL. It makes the page lose some of its HTML.


It seems to break here:

https://gyazo.com/103134b68a235d29acc0b14fbebd5265
Hmm weird. It shouldn't be doing that. I am at work but I'll be home again in 4 hours to give a better look. If you send me the source code (or rather access to the server) I'll see what's up
(Jan 29, 2017 06:03 PM)NoSuchAgency Wrote:  Hmm weird. It shouldn't be doing that. I am at work but I'll be home again in 4 hours to give a better look. If you send me the source code (or rather access to the server) I'll see what's up

Brilliant, thank you. Ill send it now
Try turning the [L] to [L,QSA]
(Jan 29, 2017 06:05 PM)NoSuchAgency Wrote:  Try turning the [L] to [L,QSA]

https://gyazo.com/920a32cc409197471998ae013b037dc1

Get a 500 error now.


(Jan 29, 2017 06:05 PM)NoSuchAgency Wrote:  Try turning the [L] to [L,QSA]

Thank you btw, I send my code over.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by ClumsyOct 31, 2024 05:53 AM 3 221 Oct 31, 2024 05:53 AM
Last Post: Nachfolger
[PHP] by MarkoTheHackerOct 29, 2024 08:56 PM 2 246 Oct 29, 2024 08:56 PM
Last Post: Clumsy
[PHP] by SkidyJun 14, 2017 05:29 AM 4 278 Jun 14, 2017 05:29 AM
Last Post: Skidy