简体   繁体   中英

PHP htaccess rewrite rules with wordpress

I have a running service that lets my user choose their own URL address (example: http://hsdfhdfghfh.com/theUserURL )

Now I'm going to put my front site on a wordpress but keep my app running along-side with it.

Now for the problem, i've set a rule in htaccess to forward my users url to their page, but wordpress also needs the same rule in order to make pretty URL (permalink).

Here is my htaccess with my code and the code that wordpress injected. Currently only my redirect is working, how can I make them both work together? Can I add a code in my php file that gets the URLs and if it has no entries I throw it to wordpress to show?

This is my htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.*)$ ./url.php?w=$1

AddDefaultCharset UTF-8

# 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

And this is my php (url.php) file that handles the redirects:

<?php

session_start();

$url_name = $_GET['w'];


include ('init.php');

$result = mysql_query("SELECT * FROM urls WHERE url='$url_name'");  
$num_rows = mysql_num_rows($result);
$query_result = mysql_fetch_assoc($result);

if($num_rows == 0){

    include($theurl.'/404.php');
    exit();
}


$_SESSION['url_id'] = $query_result['url_id'];

?>

..Shows the rest of the page for the user with the specified url_id session...

Maybe instead of showing the 404.php page I could transfer the entered URL to wordpress somehow?

Cheers!

After trying different approaches and trying to manipulate using .htaccess I realized that this process is very bad for loading times and overloading the server.

I ended up moving Laravel to a subdomain :/

Don't try to put Wordpress and Laravel together on the same domain unless you really want to tweak wordpress to the core.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM